Ich bin mit einem XML wie folgt arbeiten: (es ist ein Standard container.xml in einem epub Buch)Ist registerNamespace in DOMXPath von PHP notwendig?
<?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>
Ich versuche es mit PHP zu analysieren. Dies ist mein Code so weit:
$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.
Meine Frage ist: Gibt es eine Möglichkeit nicht, dass registerNamespace
Aufruf zu tun? Ich bin mir nicht sicher, ob verschiedene epubs diesen Wert ein bisschen anders setzen, und ich brauche diesen Code, um auf jedem epub zu arbeiten, den ich darauf werfe.