问题描述
我需要使用Java读取XML文件。其内容类似于
I need to read an XML file using Java. Its contents are something like
<ReadingFile>
<csvFile>
<fileName>C:/Input.csv</fileName>
<delimiter>COMMA</delimiter>
<tableFieldNamesList>COMPANYNAME|PRODUCTNAME|PRICE</tableFieldNamesList>
<fieldProcessorDescriptorSize>20|20|20</fieldProcessorDescriptorSize>
<fieldName>company_name|product_name|price</fieldName>
</csvFile>
</ReadingFile>
是否有任何特殊的读者/ JAR或我们应该使用 FileInputStream 阅读?
Is there any special reader/JARs or should we read using FileInputStream?
推荐答案
另一个建议:试试Commons digester。这允许您使用基于规则的方法非常快速地开发解析代码。有一个教程,图书馆是
Another suggestion: Try out Commons digester. This allows you to develop parsing code very quickly using a rule-based approach. There's a tutorial here and the library is available here
我同意Brian和Alzoid在JAXB中非常适合让您快速上手。您可以使用JDK附带的xjc绑定编译器在给定XML模式的情况下自动生成Java类。
I also agree with Brian and Alzoid in that JAXB is great to get you up and running quickly. You can use the xjc binding compiler that ships with the JDK to auto generate your Java classes given an XML schema.
这篇关于如何使用Java读取XML文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!