PHP XML Parsing

前端 未结 5 987
心在旅途
心在旅途 2020-12-14 04:55

Which is the best way to parse an XML file in PHP ?

First
Using the DOM object

//code
$dom = new DOMDocument();
$dom->load(         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-14 05:22

    It depends on the document you're passing, but XMLReader is usually the faster than both simplexml and DOM (http://blog.liip.ch/archive/2004/05/10/processing_large_xml_documents_with_php.html). Personally though I've never used XMLReader and usually decided which to use depending on whether or not I need to edit it:

    • simplexml if I'm just reading a document
    • DOM if I'm modifying the DOM and saving it back

    You can also convert objects between simplexml and DOM.

提交回复
热议问题