我正在尝试使用 simplexml 解析 Project Gutenberg catalog.rdf,如下所示Basic SimpleXML 用法:
$dom = new DOMDocument;
$dom->loadXML($etext_rdf);
if (!$dom) {
echo 'Error while parsing the document';
exit;
}
$etext= simplexml_import_dom($dom);
print_r($etext);
但 $etext 总是空的。任何提示为什么?这是我正在测试的 loadXML $etext_rdf(这里是 rdf 的来源):
<pgterms:etext rdf:ID="etext26783">
<dc:publisher>&pg;</dc:publisher>
<dc:title rdf:parseType="Literal">The Story of the Kearsarge and Alabama</dc:title>
<dc:creator rdf:parseType="Literal">Browne, A. K.</dc:creator>
<pgterms:friendlytitle rdf:parseType="Literal">The Story of the Kearsarge and Alabama by Browne</pgterms:friendlytitle>
<dc:language><dcterms:ISO639-2><rdf:value>en</rdf:value></dcterms:ISO639-2></dc:language>
<dc:subject>
<rdf:Bag>
<rdf:li><dcterms:LCSH><rdf:value>Kearsarge (Sloop)</rdf:value></dcterms:LCSH></rdf:li>
<rdf:li><dcterms:LCSH><rdf:value>Alabama (Screw sloop)</rdf:value></dcterms:LCSH></rdf:li>
<rdf:li><dcterms:LCSH><rdf:value>United States -- History -- Civil War, 1861-1865 -- Naval operations</rdf:value></dcterms:LCSH></rdf:li>
</rdf:Bag>
</dc:subject>
<dc:subject><dcterms:LCC><rdf:value>E456</rdf:value></dcterms:LCC></dc:subject>
<dc:created><dcterms:W3CDTF><rdf:value>2008-10-06</rdf:value></dcterms:W3CDTF></dc:created>
<pgterms:downloads><xsd:nonNegativeInteger><rdf:value>20</rdf:value></xsd:nonNegativeInteger></pgterms:downloads>
<dc:rights rdf:resource="&lic;" />
</pgterms:etext>