5

私は次のような XML で作業しています: (これは、epub ブックの標準のcontainer.xmlです)

<?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>

PHPを使用して解析しようとしています。これまでの私のコードは次のとおりです。

$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.

私の質問は次のとおりです。その呼び出しを行わない方法はありますか? registerNamespace異なる epub がこの値を少し異なって設定するかどうかはわかりません。私が投げた epub で動作するには、このコードが必要です。

4

2 に答える 2