Jump to content

DOM xml removeChild() when node nested deeper than 1 node


flashdomm

Recommended Posts

Hi guys,

 

I am trying to figure how to use this code when you have nodes deeper than 1 child element.

 

Here's the code from PHP Manual:

 

<?php

$doc = new DOMDocument;
$doc->load('book.xml');

$book = $doc->documentElement;

// we retrieve the chapter and remove it from the book
$chapter = $book->getElementsByTagName('chapter')->item(0);
$oldchapter = $book->removeChild($chapter);

echo $doc->saveXML();
?>

 

 

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN" 
          "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<book id="listing">
<title>My lists</title>
<chapter>blah</chapter>
</book>

 

http://www.php.net/manual/en/domnode.removechild.php

 

I am having trouble understanding third line. What does "documentElement" link to? What can I do if node in question is within more than 1 element node ??

 

I spend ages trying to figure this out but not getting anywhere, I would really really appreciate any help.

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.