How to create Java objects from XML tags which are referring each other?

后端 未结 3 998
臣服心动
臣服心动 2021-01-05 21:14

I have an XML which has tags corresponding to three types of Java objects which would be created from the XML. The objects are of the form:

A
- static Map<         


        
3条回答
  •  温柔的废话
    2021-01-05 21:42

    From what you describe this could be done with a common framework such as Spring, either by you changing your XML or generate a XSTL which creates a Spring XML config file from your XML.

    Spring Core documentation is probably enough to get you started. An example of the XML would be

    
        
        
    
    
        
        
    
    

    But what you describe should not be too hard with reflection. Assuming that none of the other objects need a reference in the constructor (but rather as setX) I would start by scanning the xml, create and store all objects with their names and remember a list of "connections" so be made. After all objects are created do all connections in the connection list.

提交回复
热议问题