Jump to content

XMLDom append_child()?


Collin

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]
Link to comment
https://forums.phpfreaks.com/topic/3650-xmldom-append_child/
Share on other sites

  • 2 years later...

Archived

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

×
×
  • Create New...

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.