简体   繁体   中英

Best way to bind a XML File in Java (NetBeans)

i want to bind this simple XML File in my java project:

<?xml version="1.0" encoding="UTF-8"?> 
<itg> 
 <reader> 
  <chapter id="1">
   <subchapter id="1"></subchapter> 
   <subchapter id="2"></subchapter>
  </chapter> 
  <chapter id="2">
   <subchapter id="1"></subchapter> 
   <subchapter id="2"></subchapter> 
  </chapter> 
  <chapter id="3"></chapter>
 </reader> 
 <questions> 
 </questions> 
</itg>

I use NetBeans, and actually i bind the XML File by parsing the xml file into a ArrayList, an bind the list. It works, but it is possible to bind the xml File in a better way?

Thanks!

For this small XML (and not only) I would recommend that you take a look at JAXB . The two basic operations are marshalling (converting Java objects to XML data) and unmarshalling (converting XML data to Java objects) but verification and so on is also provided.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM