简体   繁体   English

在Java(NetBeans)中绑定XML文件的最佳方法

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

i want to bind this simple XML File in my java project: 我想在我的Java项目中绑定这个简单的XML文件:

<?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. 我使用NetBeans,实际上我通过将xml文件解析为ArrayList(绑定列表)来绑定XML文件。 It works, but it is possible to bind the xml File in a better way? 它可以工作,但是可以用更好的方式绑定xml文件吗?

Thanks! 谢谢!

For this small XML (and not only) I would recommend that you take a look at JAXB . 对于这种小的XML(不仅是),我建议您看一下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. 编组(将Java对象转换为XML数据)和解组(将XML数据转换为Java对象)这两个基本操作,但是还提供了验证等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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