开发者

OAI Jaxen XPath problem

I'm having big problems with Xpath evaluation using Jaxen.

Here's part of XML i'm evaluating on:

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

I'm using Jaxen because in my use case it's much faster then Apache implementation. I'm using W3C DOM for XML representation.

I need to select all record arguments, and then on selected nodes evaluate other xpaths (it's needed because of my processing architecture).

I'm selecting all record nodes (this works):

/OAI-PMH/ListRecords/record

Then on every selected record node I'm evaluating other xpaths to get needed data:

Select identifier text value (this works):

header/identifier/text()

Select title text value (this does NOT work):

metadata/oai_dc:dc/dc:title/text()

I've registered namespaces prefixes with their URIs (oai_dc and dc). I also tried other xpaths but none of them work:

metadata/dc/title/text()
metadata//dc:title/text()

I've read other stackoverflow questions about xpaths, namespaces and solution to add prefix开发者_JS百科 "oai" with URI "http://www.openarchives.org/OAI/2.0/". I tried adding that "oai:" prefix to nodes without defined prefix but as result I even didn't select record nodes. Any ideas what I'm doing wrong?

Solution: Problem was about parser (thanks jasso). It wasn't set to be namespace aware - after changing that setting everything works fine, as expected.


I can't see how the XPath expression /OAI-PMH/ListRecords/record can possibly select anything, since your document does not have a {}OAI-PMH element, only a {http://www.openarchives.org/OAI/2.0/}OAI-PMH element. See http://jaxen.codehaus.org/faq.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜