开发者

XML in PHP removeChild using id

Ok, I have previously asked a similar question to this but it was voted down because there are other similar questions and thus received no answers. I'm still completely stumped, so i would appreciate any help.

The question has come up before here: How do开发者_如何学C I remove a specific node using its attribute value in PHP XML Dom?

I have adapted my code as suggested in the answers to that question and it still doesn't work.

My XML is in a similar layout to this:

<fooBar>
 <cat>
    <thing id="111">
        <title></title>
        <desc></desc>
        <link></link>
        <img></img>
    </thing>
        <thing id="222">
        <title></title>
        <desc></desc>
        <link></link>
        <img></img>
    </thing>
        .............etc
 </cat>
</fooBar>

And my PHP is as follows:

$r = $_GET['removeChild'];
$x = "upload/".($_GET['xml']);

    $doc = new DOMDocument();
                $doc->load($x);

    $xpath = new DOMXpath($doc);
                $nodeList = $xpath->query('//thing[@id="'.$r.'"]');

    if ($nodeList->length) {
        $node = $nodeList->item(0);
        $node->parentNode->removeChild($node);
    }

  $doc->saveXML();
  echo $x. "<br /> " .$r;

The correct values are being echoed and the XML file is being loaded correctly as I can see it's been modified, but nothing is removed. I have also tried hard coding a known id into the xpath line but still get the same result.I've spend the best part of a day trying to get this to work so any help is very much appreciated.


Just making sure -- you are using save to store it back to disk, right?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜