XmlWriter 与 XmlReader 的复杂用法
我将通过 xmlReader 读取文件,并通过 XmlWriter 将子元素插入到该对象中并保存输出。我如何解析这两个类之间的数据?我知道 SimpleXml 已经存在并且使它变得容易。但我有大量数据,我需要让它比 SimpleXml 更快。这只是理论,我还没有代码,我只需要通过这些问题得到答案: 创建两个对象读取器/写入器及其工作是否比通过 SimpleXml 类似更快? 如何使用 xmlReader 对象并将数据部分解析为 XmlWriter?
I im going to read file by xmlReader and insert a child elements into this object by XmlWriter and save the output. How i can parse data between this two classes? I know that SimpleXml is already exists and makes it easy. but i have a huge amount of the data and i need to make it faster then SimpleXml can. It is only teory and i havnt code yet, i need only to get answer only by these qwestions:
Is creating two objects reader/writer and their work Is faster then similar via SimpleXml ?
How does it possible to use xmlReader object and parse data parts into XmlWriter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
XMLWriter
不仅比SimpleXML
更快,而且占用的内存更少。特别是当您需要处理大量数据时(正如您所做的那样),您应该使用XMLWriter
,因为数据量较大时速度确实开始变得重要。当然,您可以同时拥有
XMLReader
和XMLWriter
。您将按照您所写的那样进行操作:从XMLReader
读取并立即将其写入XMLWriter
。编辑:我发现了一些不错的统计数据(还有代码示例)此处。阅读该文章后,我还了解到 SimpleXML 比 XMLWriter 占用的内存更少,这让我有点惊讶……所以我最初的陈述似乎只有 50% 正确。更快:是,更少的内存:否。
XMLWriter
is not only faster thanSimpleXML
, but also takes less memory. Especially when you need to handle large amounts of data (as you do), you should useXMLWriter
as with larger data speed really starts to matter.Of course, you can have a
XMLReader
and aXMLWriter
at the same time. And you would do it just as you wrote: read from theXMLReader
and write it immediately to theXMLWriter
.edit: I found some nice statistics (and also a code sample) here. Reading that, I also learned that SimpleXML takes less memory than the XMLWriter, which surprises me a little...so my initial statement seems to be only 50% true. Faster: yes, less memory: no.