开发者

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

开发者 https://www.devze.com 2023-02-10 07:06 出处:网络
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 p

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

精彩评论

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

关注公众号