Jump to content

Archived

This topic is now archived and is closed to further replies.

Collin

XMLDom append_child()?

Recommended Posts

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: [b]domnode::append_child() expects parameter 1 to be object[/b]

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 [b]new[/b] document, and not an existing one? Or can't I add anything using xpath?

This is the code:
[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");
                $currentNode->append_child($newNode);
            }
        }
[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.