Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Problema con query xpath

    Salve,
    ho questo file xml
    codice:
    <?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>
    e questo codice php
    Codice PHP:
    <?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); // rimuove il nodo <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"// non lo stampa
    }
    $doc->save("online.xml");
    echo 
    "finished";
    ?>
    Ora, ho un problema, suppongo con la query xpath (che mi sembra giusta) poichè il ciclo foreach viene eseguito 0 volte, non riesco a capire cosa sbaglio
    Grazie

    Patrick

  2. #2
    Codice PHP:
    $id "'id35'"
    L'errore è nella sintassi che è
    [@id = 'id35']
    come facevi tu diventava
    [@id = id35]

    Per le query ho trovato molto utile Visual XPath


    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  3. #3

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.