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.

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.