code4lib / ruby-oai

a Ruby library for building OAI-PMH clients and servers
MIT License
62 stars 43 forks source link

libxml and xpath #12

Closed atomotic closed 12 years ago

atomotic commented 12 years ago

i would subclass OAI::IdentifyResponse and add a new attr

@sampleIdentifier = xpath(doc, '..//sampleIdentifier')

to read sampleIdentifier from description, like:

<description>
  <oai-identifier xmlns="http://www.openarchives.org/OAI/2.0/oai-identifier"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.openarchives.org/OAI/2.0/oai-identifier
      http://www.openarchives.org/OAI/2.0/oai-identifier.xsd">
    <scheme>oai</scheme> 
    <repositoryIdentifier>  ...  </repositoryIdentifier>    
    <delimiter>:</delimiter> 
    <sampleIdentifier>oai::... </sampleIdentifier>
  </oai-identifier>
</description>

this works only with REXML but no with libxml, i guess due to namespaces. hints to solve this?

atomotic commented 12 years ago

i founded a solution for default namespaces reading: http://libxml.rubyforge.org/rdoc/classes/LibXML/XML/XPath.html

i added this two methods to my subclassed OAI::IdentifyResponse

def repositoryIdentifier
  return doc.find('.//oai:repositoryIdentifier', "oai:http://www.openarchives.org/OAI/2.0/oai-identifier").first.content
end
def sampleIdentifier
  return doc.find('.//oai:sampleIdentifier', "oai:http://www.openarchives.org/OAI/2.0/oai-identifier").first.content
end