gpt4 book ai didi

java - XMLStreamReader 和 XMLEventReader 有什么区别?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:19:27 25 4
gpt4 key购买 nike

我在网上冲浪。我发现 XMLStreamReader用于解析 XML 的游标样式 APIXMLEventReaderIterator style API for Parsing XML。有人能详细告诉我吗?

最佳答案

看看解释:https://www.ibm.com/developerworks/library/x-stax1/

Both XMLStreamReader and XMLEventReader allow the application to iterate over the underlying XML stream on its own. The difference between the two approaches lies in how they expose pieces of the parsed XML InfoSet. The XMLStreamReader acts as a cursor that points just beyond the most recently parsed XML token and provides methods for obtaining more information about it. This approach is very memory-efficient as it does not create any new objects. However, business application developers might find XMLEventReader slightly more intuitive because it is actually a standard Java Iterator that turns the XML into a stream of event objects. Each event object in turn encapsulates information pertaining to the particular XML structure it represents. Part 2 of this series will provide a detailed description of the event iterator-based API. As to which API style to use depends on the situation. The event iterator-based API represents a more object-oriented approach than the cursor-based API. As such, it is easier to apply in modular architectures, because the current parser state is reflected in the event object; thus, an application component does not need access to the parser/reader while processing the event. Furthermore, it is possible to create an XMLEventReader from an XMLStreamReader using XMLInputFactory's createXMLEventReader(XMLStreamReader) method.

关于java - XMLStreamReader 和 XMLEventReader 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36717402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com