Jump to content


XMLDom append_child()?

  • Please log in to reply
1 reply to this topic

#1 Collin

  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 26 February 2006 - 11:36 PM

Hello all! :)

I've run in a bit of trouble and can't figure out what's wrong...

I'm using PHP5 I have an xml document and I want to edit it. It's used for making a navigation tree, so it's full of "url" tags... I can read it (the navigation tree shows up you as I want it), I can change values and attributes of tags in the xml document, but I cannot add new nodes to the document... :(

It's quite straight forward: create an element, and add it to the end of the children of a node. The problem is that the "create_element()" method doesn't return an object. In fact it doesn't return anything I can detect... :( the error is: domnode::append_child() expects parameter 1 to be object

I've read up on this, and most problems arise from not enabling the XMLDOC extension in the PHP.ini, but since I can do all things "dom", I don't think the extension is the problem... Other than that I haven't found any real solutions... :(

Maybe there is something... Can you only add new nodes to a new document, and not an existing one? Or can't I add anything using xpath?

This is the code:
        global $xPath,$xmlDoc,$root;
        $xPathResult = xpath_eval($xPath, "//@id");
        foreach ($xPathResult->nodeset as $currentNode)
             if ($currentNode->value == $_GET['lte'])
                $currentNode = $currentNode->parent_node();
                $newNode = $xmlDoc->create_element("url");

#2 bnmng

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 17 March 2008 - 10:52 PM

I think you need appendchild and createelement without the underscores.  If you're using PHP5, then look for DOM command, instead of  XMLDOM commands.  Info here: http://us3.php.net/dom

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users