开发者

XML to Java Object only using Java5 (no external libs)

normally I would use JaxB, XMLBeans or Simple to convert a XML file to a Java Object. In this case I can however only use Java5 and no external libraries (for several reasons开发者_如何学Python).

What is the best way to do that? My XML input is very simple. What is the most flexible and elegant way to get the XML into a Java-Object (I don't really need real JavaBeans, since I just need GETTER).

Thanks!


Well, you can do that using DOM implementation.


Java5 provides JaxP which includes DOM and SAX.

Which one to use depends largely on how big the XML document is and how fast you need to access elements. DOM will put the whole XML structure into memory, while SAX provides a serial streaming approach.


The most flexible way to do data binding is by using XPath see the article below http://onjava.com/pub/a/onjava/2007/09/07/schema-less-java-xml-data-binding-with-vtd-xml.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜