XmlWriter 与 XmlReader 的复杂用法

发布于 2024-12-29 06:28:57 字数 234 浏览 0 评论 0原文

我将通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

著墨染雨君画夕 2025-01-05 06:28:57

XMLWriter 不仅比 SimpleXML 更快,而且占用的内存更少。特别是当您需要处理大量数据时(正如您所做的那样),您应该使用 XMLWriter,因为数据量较大时速度确实开始变得重要。

当然,您可以同时拥有 XMLReaderXMLWriter。您将按照您所写的那样进行操作:从 XMLReader 读取并立即将其写入 XMLWriter

编辑:我发现了一些不错的统计数据(还有代码示例)此处。阅读该文章后,我还了解到 SimpleXML 比 XMLWriter 占用的内存更少,这让我有点惊讶……所以我最初的陈述似乎只有 50% 正确。更快:是,更少的内存:否。

XMLWriter is not only faster than SimpleXML, but also takes less memory. Especially when you need to handle large amounts of data (as you do), you should use XMLWriter as with larger data speed really starts to matter.

Of course, you can have a XMLReader and a XMLWriter at the same time. And you would do it just as you wrote: read from the XMLReader and write it immediately to the XMLWriter.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文