What to use for XML parsing / reading in PHP4

后端 未结 7 858
陌清茗
陌清茗 2020-12-21 16:00

Unfortunatly I have to work in a older web application on a PHP4 server; It now needs to parse a lot of XML for calling webservices (custom p

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-21 16:50

    I would definitely recommend the SimpleXML backport, as long as its performance is good enough for your needs. The demonstrations of xml_parse look simple enough, but it can get very hairy very quickly in my experience. The content handler functions don't get any contextual information about where the parser is in the tree, unless you track it and provide it in the start and end tag handlers. So you're either calling functions for every start/end tag, or throwing around global variables to track where you are in the tree.

    Obviously the SimpleXML backport will be a bit slower, as it's written in PHP and has to parse the whole document before it's available, but the ease of coding more than makes up for it.

提交回复
热议问题