简体   繁体   English

并行解析xml文件的最快方法是什么?

[英]What is the fastest way to parse xml files in parallel?

I need to use XmlDocument or HAP to parse several files, what is the fastest way to do it? 我需要使用XmlDocument或HAP来解析多个文件,最快的方法是什么? I have an i7 processor, but the processor is using hardly 30% no matter how many threads I use. 我有一个i7处理器,但是无论我使用多少线程,该处理器都几乎没有使用30%的内存。 Each thread parses a different file. 每个线程解析一个不同的文件。

System.Xml.Linq.XElement.Parse() is faster than XmlDocument.LoadXml() for parsing XML strings, and XElement.Load() will parse directly from a file. System.Xml.Linq.XElement.Parse()解析XML字符串的速度比XmlDocument.LoadXml()快,并且XElement.Load()将直接从文件中解析。 You may also find LINQ to XML much easier to use. 您可能还会发现LINQ to XML更加易于使用。

But if you want to work with XmlDocument, then you can use 但是,如果您要使用XmlDocument,则可以使用

XmlDocument xml = new XmlDocument();
xml.LoadXml(XElement.Load(someFileName).ToString(SaveOptions.DisableFormatting));

And as others suggested, you probably won't hit 100% CPU utilization since the i7 may parse much faster than the hard disk can send data. 正如其他人所建议的那样,您可能不会达到100%的CPU利用率,因为i7的解析速度可能比硬盘发送数据的速度快得多。

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

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