Marian Kostadinov wrote:
//But how can I understand what is the name of the root node?
$dom_sxe = dom_import_simplexml($sxe1);
//Hooray, we've got node name
echo $dom_sxe->nodeName;
//And what happens if element sequence changes? .
echo
$dom_sxe->childNodes->item(1)->firstChild->firstChild->firstChild->nodeValue;
//... hm... I prefer SimpleXML.
The API is to be kept simple and what you are asking for can be done
extending the SimpleXMLElement and the functions are a whole 1 line of
user code:
<?php
class cNode extends SimpleXMLElement {
function getName() {
return dom_import_simplexml($this)->nodeName;
}
function getType() {
return dom_import_simplexml($this)->nodeType;
}
}
$xml = '<root />';
$sxe = simplexml_load_string($xml, 'cNode');
print $sxe->getName()."\n";
print $sxe->getType()."\n";
?>
Of course XPath could be used in place of DOM too though.
Rob
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php