Jump to content

[SOLVED] Deleting a node with known position in DOM (XML)


spamgoat

Recommended Posts

Hey all,

 

I have a a xml with a very basic structure:

 

<root>
  <template name="name0">data0</template>
  <template name="name1">data1</template>
  <template name="name2">data2</template>
  <template name="name3">data3</template>
  <template name="name4">data4</template>
  <template name="name5">data5</template>
  <template name="name6">data6</template>
</root>

 

I'm trying to remove the 4th node in the file (named name3). The code i'm using for this is:

 

<?
    $i = 3; //Hoping to delete the 4th node.
    $doc = new DOMDocument(); $doc->load('file:///var/templates.xml'); 

    $items = $doc->getElementsByTagName('template'); $items2 = $items->item($i);
    $itemg = $items2->nodeValue; echo $itemg; //It does return the value of the item i'm trying to delete.

    $itemg = $items->removeChild($items2); //Return: "Fatal error: Call to undefined method DOMNodeList::removeChild()"
?>

 

As said above, the script return Fatal error: Call to undefined method DOMNodeList::removeChild().

 

I've no idea why it isn't working, and definitely not an idea what the correct code would be.

 

Any help would be highly appreciated,

spamgoat

Link to comment
Share on other sites

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.