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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.