Jump to content

[SOLVED] Problem with xpath query


patrick91

Recommended Posts

Hello this is my first post :D

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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