简体   繁体   中英

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. For example, the node Stats may have 50 child nodes all named user and 10 child nodes named 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. 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> . 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 ?

I am looking for general advice regarding parsing XML files in PHP, with emphasis on speed. 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.

he's got a point. use xml_parser. it's an event driven parser for xml.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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