Jump to content

paragpdoke

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

paragpdoke's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. 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.
×
×
  • 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.