简体   繁体   English

速度:DOMDocument与xml_parse_into_struct与strrpos

[英]Speed: DOMDocument vs xml_parse_into_struct vs strrpos

I'm trying to rip values from a simple XML file that contains duplicate nodes under the same name. 我试图从一个简单的XML文件中提取值,该文件包含相同名称下的重复节点。 For example, the node Stats may have 50 child nodes all named user and 10 child nodes named Finances . 例如,节点Stats可能有50个子节点(均名为user和10个子节点(名为Finances

For a very large number of child nodes with the same name, I do not know of any way to use xml_parse_into_struct, so I normally use DOMDocument. 对于具有相同名称的大量子节点,我不知道使用xml_parse_into_struct的任何方式,因此我通常使用DOMDocument。 However, say if all nodes had unique names, which would be faster between the three? 但是,假设所有节点都具有唯一名称,那么这三个节点之间哪个更快? Sometimes I would use strrpos to get the position of say, <cash> and then search for the next occurrence of </cash> . 有时我会使用strrpos来获取<cash>的位置,然后搜索</cash>的下一个出现位置。 I would continue until I'm done through the document. 在完成本文档之前,我将继续。 However, how does this compare with DOMDocument's getElementsByTagName('cash') and xml_parse_into_struct ? 但是,这与DOMDocument的getElementsByTagName('cash')xml_parse_into_struct如何?

I am looking for general advice regarding parsing XML files in PHP, with emphasis on speed. 我正在寻找有关在PHP中解析XML文件的一般建议,重点是速度。 I normally use DOMDocument for everything because it is most convenient, but when I have to load 100 thousand XML files, any increases in speed is much appreciated. 我通常将DOMDocument用于所有内容,因为它最方便,但是当我必须加载10万个XML文件时,任何速度上的提高都值得赞赏。

he's got a point. 他有一点。 use xml_parser. 使用xml_parser。 it's an event driven parser for xml. 这是xml的事件驱动解析器。

http://php.net/manual/en/book.xml.php http://php.net/manual/zh/book.xml.php

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

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