Jump to content

Recommended Posts

Hello Everyone.

I'm new to PHP and I'm trying to get some XML manipulation working.

Somehow I can't get the remove_child method to work for me. Here are

the details:

 

XML structure:

<?xml version="1.0"?>
<?xml-stylesheet type='text/xsl' href='myXSL.xsl'?>
<ServerList>
<Server id="myServer1">
     <!--Some tags here. These tags have no children-->
     <Tag1>AAA1</Tag1>
     <Tag2>BBB2</Tag2>
     <TagN>ZZZ3</TagN>
</Server>
<Server id="myServer2">
     <!--Some tags here. These tags have no children-->
     <Tag1>AAA4</Tag1>
     <Tag2>BBB5</Tag2>
     <TagN>ZZZ6</TagN>
</Server>
</ServerList>

I'm trying to capture some _REQUEST variables and create a new server

node in the XML DOM. Before this, I query the DOM using xpath and the

server id. If the server is found, I intend to delete that node and

rest of the php code (creation of the new server node) follows

suitably.

 

PHP code excerpt:

$dom=new DOMDocument();
$dom->load("myXML.xml");
$myXpath=new Domxpath($dom);
//$ServerID is populated correctly based on _REQUEST variables.
$myQuery="/ServerList/Server[@id='".$ServerID."']";
$result=$myXpath->query($myQuery);
if (($result->length) == 1) {
//What follows is line # L
$dom->document_element->remove_child($result->item(0));
}
//Some more code...probably irrelevant at this moment.

The error I'm observing is:

Fatal error:  Call to a member function remove_child() on a non-object
in myPHP.php on line L.

 

The page at:

http://www.php.net/manual/en/function.domdocument-document-element.php

has a comment saying "documentElement" should be used in PHP 5 rather

than "document_element". With that change, I'm running into a new

error with PHP 5.2.5.

 

How to use the remove_child method if it belongs to a DOMNode and not

a DOMElement ? Or rather, how to convert output of

DOMDocument->documentElement to type DOMNode so that the remove_child

method is supported ?

 

Thanks in advance,

Parag P. Doke

http://paragpdoke.blogspot.com

PS: If my problem is unclear, please do let me know.

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.