Sto lavorando con un XML come questo: (si tratta di uno standard container.xml in un libro epub)È necessario registerNamespace nel DOMXPath di PHP?
<?xml version="1.0"?>
<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
<rootfiles>
<rootfile full-path="OEBPS/9780765348210.opf" media-type="application/oebps-package+xml"/>
</rootfiles>
</container>
Sto cercando di analizzarlo utilizzando PHP. Questo è il mio codice finora:
$c = new DOMDocument();
$c->load($filename);
$x = new DOMXPath($c);
//fine up to here!
//is this even what I'm supposed to be doing?
$x->registerNamespace('epub', 'urn:oasis:names:tc:opendocument:xmlns:container');
$root = $x->query('/epub:container/epub:rootfiles/epub:rootfile');
//fine down from here!
$opf = $root->item(0)->getAttribute('full-path'); //I know I should check if the element's there and if it has the attribute. Not important.
La mia domanda è: C'è un modo per non farlo registerNamespace
chiamata? Non sono sicuro che epub diversi impostino questo valore in modo un po 'diverso, e ho bisogno di questo codice per lavorare su qualsiasi epub che lancio.