PHP XML Reader


XMLReader Open

You can either open an XML file with
XMLReader::open($xmlfile)
or set the xml directly with
XMLReader::xml($xml)


XMLReader Example


$xmlread = new XMLReader();
$xmlread->xml($xmlresp);

$xmlread->read();   // read /Root
$xmlread->read();   // read first element /Element

while (true) {      // loop through all elements at this level
  echo $xmlread->name.' '.$xmlread->nodeType.PHP_EOL;
  if (!$xmlread->next()) break;
}
exit;


Copy XMLReader node into a DOMDocument

Once you've got an XML Reader node you can convert it into a DOM Document node by using expand, importNode and appendChild

$rnode = $reader->expand();
$dom = new DOMDocument();
$dnode = $dom->importNode($rnode,true)// recursively = true
$dom->appendChild($dnode);      // append childnode to DOM Document root node



REFERRERS
PhpXml
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki