Is there any way to take an unknown schema xml file and convert the values, tags, etc from the xml file into pojo? I looked at jaxb and it seems like the best way to use that is if you already know the xml schema. So basically, I want to be able to parse the tags from the xml put each into its own object maybe through the use of an arraylist. Did I just not fully understand what jaxb can or is there a better tool that can do this, or is it just too hard to implement?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- Illegal to have multiple roots (start tag in epilo
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
In the hope that this helps you to understand your situation!
The NodeList nodes contains all element nodes, in document order (opening tag). Thus, elements contained within elements will be in that list, all alike. To obtain the attributes of a node, call
The text content of a node is available by
but be aware that calling this returns the text in all elements of a subtree.
OTOH, you may call
to obtain the root element and then descend the tree recursively by calling
Element.getChildNodes()
and process the nodes (Element, Attr, Text,...) one by one. Also, note thatNode.getParentNode()
returns the parent node, so you could construct the XPath for each node even from the flat list by repeating this call to the root.It simply depends what you expect from the resulting data structure (what you call ArrayList). If, for instance, you create a generic element type (MyElement) containing one map for attributes and another one for child elements, the second map would have to be
to provide for repeated elements - which makes access to elements occurring only once a little awkward.
I hope that I have illustrated the problems of generic XML parsing, which is not a task where JAXB can help you.