XML Parsing and deserialization

前端 未结 2 1641
旧巷少年郎
旧巷少年郎 2020-12-11 08:44

I have a xml file which Im reading it from my class


new SomeClass1()
new SomeClass2()

        
相关标签:
2条回答
  • 2020-12-11 09:14

    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.

    0 讨论(0)
  • 2020-12-11 09:17

    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");          
    
    0 讨论(0)
提交回复
热议问题