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

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.