XML Parsing and deserialization

余生颓废 提交于 2019-11-28 12:37:30
Yogendra Singh

You may want to use simple Java Libraries such as XStream, which is very simple to use. All you need to define a POJO class to hold the parse values from XML and then use the library to parse the XML and produce the converted java objects for you.

     XStream xstream = new XStream();

     //converting object to XML
     String xml = xstream.toXML(myObject);

     //converting xml to object
     MyClass myObject = (MyClass)xstream.fromXML(xml);

Please have a look at its two minutes tutorial.

Mamadou

its something like that i imagine

DocumentBuilder db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse("name_of_file.xml");

Element rootElement = doc.getDocumentElement();
NodeList nl=rootElement.getElementsByTagName("TestClass");          
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!