patrick91 Posted February 6, 2008 Share Posted February 6, 2008 Hello this is my first post I' ve this xml file <?xml version="1.0" standalone="yes"?> <!DOCTYPE lista [ <!ELEMENT lista (utente)*> <!ELEMENT utente (richieste)?> <!ELEMENT richieste (richiesta)*> <!ELEMENT richiesta (#PCDATA)> <!ATTLIST utente id ID #REQUIRED> <!ATTLIST richiesta da IDREF #REQUIRED> ]> <lista> <utente id="id14"> <richieste> <richiesta da="id35"/> <richiesta da="id35"/> </richieste> </utente> <utente id="id35"/> </lista> And this php file <?php error_reporting(E_ALL); $id = 'id35'; $doc = new DomDocument; $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $doc->validateOnParse = true; $doc->Load('online.xml'); $root = $doc->documentElement; $utente = $doc->getElementById($id); $eliminato = $root->removeChild($utente); // removed the node <utente id="id35"/> $xpath = new DOMXPath($doc); $expr = "/lista/utente/richieste/richiesta[@da=$id]"; $entries = $xpath->query($expr); foreach ($entries as $entry) { $parent = $entry->parentNode; $parent->removeChild($entry); echo "test"; // print 0 time } $doc->save("online.xml"); echo "finished"; ?> Well, i've a problem with the xpath query (I think), but I don't know how resolve this problem (The foreach cicle doesn't print anything) Thanks Patrick Link to comment https://forums.phpfreaks.com/topic/89781-solved-problem-with-xpath-query/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.