问题描述
|
我在使用Jaxen进行Xpath评估时遇到了大问题。
我正在评估XML的以下部分:
<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>
<OAI-PMH xmlns=\"http://www.openarchives.org/OAI/2.0/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd\">
<responseDate>2011-05-31T13:04:08+00:00</responseDate>
<request MetadataPrefix=\"oai_dc\" verb=\"ListRecords\">http://citeseerx.ist.psu.edu/oai2</request>
<ListRecords>
<record>
<header>
<identifier>oai:CiteSeerXPSU:10.1.1.1.1484</identifier>
<datestamp>2009-05-24</datestamp>
</header>
<Metadata>
<oai_dc:dc xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:oai_dc=\"http://www.openarchives.org/OAI/2.0/oai_dc/\" xsi:schemaLocation=\"http://www.openarchives.org/OAI/2.0/oai_dc/ http://www.openarchives.org/OAI/2.0/oai_dc.xsd\">
<dc:title>Winner-Take-All..</dc:title>
<dc:relation>10.1.1.134.6077</dc:relation>
<dc:relation>10.1.1.65.2144</dc:relation>
<dc:relation>10.1.1.54.7277</dc:relation>
<dc:relation>10.1.1.48.5282</dc:relation>
</oai_dc:dc>
</Metadata>
</record>
<resumptionToken>10.1.1.1.2041-1547151-500-oai_dc</resumptionToken>
</ListRecords>
</OAI-PMH>
我使用Jaxen是因为在我的用例中,它比Apache实施要快得多。我正在使用W3C DOM进行XML表示。
我需要选择所有记录参数,然后在选定的节点上评估其他xpath(由于我的处理体系结构,因此需要它)。
我正在选择所有记录节点(可行):
/OAI-PMH/ListRecords/record
然后在每个选定的记录节点上,我正在评估其他xpath以获取所需的数据:
选择标识符文本值(有效):
header/identifier/text()
选择标题文本值(这不起作用):
Metadata/oai_dc:dc/dc:title/text()
我已经用其URI(oai_dc和dc)注册了名称空间前缀。我也尝试了其他xpath,但是它们都不起作用:
Metadata/dc/title/text()
Metadata//dc:title/text()
我已经阅读了有关xpath,名称空间和使用URI \“ http://www.openarchives.org/OAI/2.0/ \”添加前缀\“ oai \”的解决方案的其他stackoverflow问题。我尝试将\“ oai:\”前缀添加到没有定义前缀的节点,但是结果我什至没有选择记录节点。有什么想法我做错了吗?
解:
问题在于解析器(感谢jasso)。并未将其设置为可识别名称空间-更改设置后,一切按预期正常进行。
解决方法
我看不到XPath表达式
/OAI-PMH/ListRecords/record
如何选择任何内容,因为您的文档没有{}OAI-PMH
元素,而只有{http://www.openarchives.org/OAI/2.0/}OAI-PMH
元素。参见http://jaxen.codehaus.org/faq.html