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:
Expand|Select|Wrap|Line Numbers
- <?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>
PHP code excerpt:
Expand|Select|Wrap|Line Numbers
- $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.
Expand|Select|Wrap|Line Numbers
- Fatal error: Call to a member function remove_child() on a non-object in myPHP.php on line L.
Thank you in advance,
Parag P. Doke