XML Parsing and deserialization

前端 未结 2 1648
旧巷少年郎
旧巷少年郎 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.

提交回复
热议问题