开发者

How to convert any input XML file to similar Java object structure?

Hi all can any one tell me is it possible 开发者_如何学Cto convert any XML file file to equivalent java object using java?


You want a DOM parser. There are many around, a Google search for "Java DOM parser" will help you. Take this page for example.


You are probably looking for JAXB.


Use XStream library it is quite simple: http://x-stream.github.io/tutorial.html

                // object -> XML -> File 
    XStream xstream = new XStream(driver);
    String data = xstream.toXML(metaData);

                //  XML -> object
    XStream xstream = new XStream(new JettisonMappedXmlDriver());
    YourClass obj = (UourClass)xstream.fromXML(jSON);


You could use unmarshall function in castor.


Let me add another to the collection.

Have a look at the Apache Jakarta Digester this is what Tomcat uses to automap XML files (like server.xml).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜