java 最佳选择 - Spring XML 解析以读取某些元素
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26026684/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best options for - Spring XML parsing to read certain elements
提问by ram
I have read the spring documentation for reading/writing the XML documents..(http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/oxm.html) The options provided using different typs of marshalling(Oxm, Jaxb, jibx, castor, xstream) all seems to be using the conversion of a document based on some mapping file or a java bean or identifying by comparing each individual element using xstream.
我已经阅读了用于读取/写入 XML 文档的 spring 文档..( http://docs.spring.io/spring-framework/docs/current/spring-framework-reference/html/oxm.html) 使用提供的选项不同类型的编组(Oxm、Jaxb、jibx、castor、xstream)似乎都在使用基于某个映射文件或 java bean 的文档转换,或者通过使用 xstream 比较每个单独的元素来识别。
I have a requirement, where i will get big xml files and i need to read some of the elements only in it and i dont want to keep the complete xml into the memory.
我有一个要求,在那里我将获得大的 xml 文件,我只需要读取其中的一些元素,我不想将完整的 xml 保留在内存中。
What are the options that i have in spring? if any of the options that the spring documentation provides and useful for my requirement, please provide some examples.
我在春天有哪些选择?如果 spring 文档提供的任何选项对我的要求有用,请提供一些示例。
BTW, i am using latest spring 4... FYI.
顺便说一句,我正在使用最新的 spring 4 ......仅供参考。
回答by selvinsource
For large XML file you would need a SAX parser which is an event based parser.
对于大型 XML 文件,您需要一个 SAX 解析器,它是一个基于事件的解析器。
Here an example http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/
这里有一个例子 http://www.mkyong.com/java/how-to-read-xml-file-in-java-sax-parser/
Spring Object/XML Mapping is to convert XML to and from an object which is a different use case.
Spring Object/XML Mapping 是将 XML 与对象相互转换,这是一个不同的用例。