XML parser class with reference to parent element

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi guys!

I have been looking for a PHP5 class like SimpleXMLElement with the
additional feature of being able to reach the parent of its element

For example consider the following example:

$xmlObject = simplexml_load_string(<<<END

  <chapter id = "1"></chapter>
  <chapter id = "2"></chapter>


function foo($xmlObject) {
    // here I would like to be able to access book from element chapter
    // for instance something like this:
    // $parent = $xmlObject->getParent()
    // or:
    // $parent = $xmlObject->book


I have already tried searching with Google and have already looked at
PHPClasses.org but I have not found anything. In spite of this I am
sure that a solution only I cannot find it.

Thanks in advance for your help


Re: XML parser class with reference to parent element

Quoted text here. Click to load it

If you use a slightly more complex class, you can use xPath instead and use context(-2) to find parent elements and their row

-Mike PII

Site Timeline