Jump to content

tvks

Members
  • Posts

    3
  • Joined

  • Last visited

About tvks

  • Birthday 06/07/1977

Contact Methods

  • Website URL
    http://

tvks's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. tvks

    PHP and XML

    Hi Robot,My compiler is throwing me an error on execution of your program. Warning: DOMXPath::query() [function.DOMXPath-query]: Invalid predicate in try_me.php on line 5Warning: DOMNode::removeChild() expects parameter 1 to be DOMNode, boolean given in try_me.php on line 7 I am new to php and am hence dumb folded. Kindly help me.With regards,tvks
  2. tvks

    PHP and XML

    Hi,I have a simple PHP code $dom = new DomDocument;$dom->Load('test.xml');$xpath = new DOMXpath($dom);$node = $xpath->query('/contacts')->item(0);echo $node->nodeName . "\n";$GLOBALS['dom']->removeChild($GLOBALS['dom']->lastChild);$dom->save('test.xml'); and an XML file named 'test.xml' <?xml version="1.0" encoding="ISO-8859-1"?> <contacts> <entry uri="sip:vinayg@company.org"> <name>Vinay</name> <sip> sip:vinayg@company.org </sip> <Number> 9885821530 </Number> </entry> <entry uri="sip:vivek@company.org"> <name>Vivek</name> <sip> sip:vivek@company.org </sip> <Number> 9885821530 </Number> </entry> </contacts> My intention of this program is to delete only the entry tag with uri as 'sip:vivek@company.org' and all its child nodes (name, sip and Number). When I execute the above code the whole file is erased and there is no error or warning. Where am I wrong ?I would be happy for any help in correcting my code or redoing it as I am new to PHP and XML.My desired output of test.xml after execution is: <?xml version="1.0" encoding="ISO-8859-1"?> <contacts> <entry uri="sip:vinayg@company.org"> <name>Vinay</name> <sip> sip:vinayg@company.org </sip> <Number> 9885821530 </Number> </entry> </contacts> Thanx in advance.Regards,tvks
  3. tvks

    XML Deletion

    Hi,I had gone through the code in w3schools in the following addresshttp://www.w3schools.com/dom/met_element_removechild.aspI used it in my php program with a few minor modifications. My code is listed below: <html><head><script type="text/javascript" src="loadxmldoc.js"> </script></head><body><script type="text/javascript">//check if the last node is an element nodefunction get_lastchild(n){var x=n.lastChild;while (x.nodeType!=1){x=x.previousSibling;}return x;}xmlDoc=loadXMLDoc("books.xml");document.write("Number of book nodes: ");document.write(xmlDoc.getElementsByTagName('book').length);document.write("<br />");var lastNode=get_lastchild(xmlDoc.documentElement);var delNode=xmlDoc.documentElement.removeChild(lastNode);document.write("Number of book nodes after removeChild(): ");document.write(xmlDoc.getElementsByTagName('book').length);</script></body></html> When I executed this it is displaying me an output "Node removed: price" but there is no change in the file books.xml.Kindly help.Regards.
×
×
  • Create New...