xml - How to get a specific tag in a DOMDocument in PHP? -


I have variable documents that I need to modify on the fly. For example, I may have a document:

   

It is very simple, but I have tags with the same name at different levels. I want to get the item tag in 'Tag 2', in which files I have given, they have unique IDs to isolate some other attributes along with their actual tags. I have to find the tag, comment it and XML Need to save. I was able to get the DOMDocument back to 'Tag 2' node, but I'm not sure how to use item tags in that structure.

This is a problem that excel in PHP class first load (HTML) Load the XML string using the method, and then use an XPath expression to cross the DOM tree:

  $ dom = new DOMDocument; Libxml_use_internal_errors (true); $ Dom- & gt; LoadHTML ($ HTML); $ Xpath = new DOMXPath ($ dom); $ Item_tags = $ xpath- & gt; Query ('// tag2 / item'); Forex currency ($ item_tags as $ tag) {ebb $ tag- & gt; Tagname, php_eol; // example}  


Comments