SimpleXML: Mixing With DOM Interoperability


PHP SimpleXML Step By Step Tutorial - Part 7: When we work with unknown elements, we can use DOM interoperability. First, we import nodes into the DOM extension. Next, access them using DOM properties and methods. See this sample:
<?php
$lib  = simplexml_load_file("test.xml");

$children = $lib->book->children();

foreach($children as $child){
  $element = dom_import_simplexml($child);
  $name = $element->nodeName;
  print $name.": ".$child;
  
}

?>

You may get like this:

id: 1title: PHP AJAXauthor: Andreasdescription: This is good book for learning AJAXon_sale: 1

After importing nodes to the DOM extension, we can perform anything that supported by DOM like add new element, edit, or remove element.



Series this article:
SimpleXML: Creating a SimpleXMLElement
SimpleXML: Creating XML Document From Database
SimpleXML: Accessing Element
SimpleXML: Using Iterable Object
SimpleXML: Accessing Unknown Element
SimpleXML: Creating File Contain Part of Another XML Document
SimpleXML: Mixing With DOM Interoperability

Bookmark and Share Tag: SimpleXML, SimpleXMLElement, XML, DOM Category: PHP Basic Post : April 17th 2008 Read: 27,948

advertisements


blog comments powered by Disqus