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

  • 2 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.