How to deserialize Java objects from XML?

后端 未结 5 742
暗喜
暗喜 2021-01-16 08:01

I\'m sure this might have been discussed at length or answered before, however I need a bit more information on the best approach for my situation...

Problem

5条回答
  •  迷失自我
    2021-01-16 08:26

    JAXB, the Java API for XML Binding might be what you want. You use it to inflate an XML document into a Java object graph made up of "Java content objects". These content objects are instances of classes generated by JAXB to match the XML document's schema

    But if you already have a set of Java classes, or don't yet have a schema for the document, JAXB probably isn't the best way to go. I'd suggest doing a SAX parse and then building up your Java objects during the parse. Alternatively you could try a DOM parse and then walk the resulting Document tree to pull out the parts of interest (maybe with XPath) -- but 5MB of XML might turn into 50MB of DOM tree objects in Java.

提交回复
热议问题