简体   繁体   English

以通用方式在java中读取XML数据

[英]Reading XML data in java in generic way

How to read data from a XML file in a generic way.generic way means in the sense idf I change the XML file at a later time no impact will be there to the out put format.如何以通用方式从 XML 文件中读取数据。通用方式意味着在 idf 的意义上,我稍后更改 XML 文件不会对输出格式产生影响。 It should read the whole content of the XML file perfectly in key value pair.它应该在键值对中完美地读取 XML 文件的全部内容。

You should try with a SAX Parser and put the key/value pairs in a Map.您应该尝试使用 SAX 解析器并将键/值对放在 Map 中。

http://docs.oracle.com/javase/7/docs/api/org/xml/sax/helpers/DefaultHandler.html http://docs.oracle.com/javase/7/docs/api/org/xml/sax/helpers/DefaultHandler.html

Using this Handler you can simply parse it from start to end.使用此处理程序,您可以简单地从头到尾解析它。

See also here for an example.另请参见此处的示例。

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

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