diff --git a/lib/oai/client/response.rb b/lib/oai/client/response.rb index 25e41a7..265a657 100644 --- a/lib/oai/client/response.rb +++ b/lib/oai/client/response.rb @@ -18,11 +18,13 @@ module OAI # ``` class Response include OAI::XPath - attr_reader :doc, :resumption_token, :resumption_block + attr_reader :doc, :resumption_token, :resumption_block, :complete_list_size def initialize(doc, &resumption_block) @doc = doc - @resumption_token = xpath(doc, './/resumptionToken') + rt_node = xpath_first(doc, './/resumptionToken') + @resumption_token = get_text(rt_node) + @complete_list_size = get_attribute(rt_node, 'completeListSize') @resumption_block = resumption_block # throw an exception if there was an error diff --git a/lib/oai/xpath.rb b/lib/oai/xpath.rb index 85c70da..0bd9df5 100644 --- a/lib/oai/xpath.rb +++ b/lib/oai/xpath.rb @@ -22,12 +22,16 @@ def xpath_first(doc, path) # get text for first matching node def xpath(doc, path) el = xpath_first(doc, path) - return unless el - case parser_type(doc) + get_text el + end + + def get_text(node) + return unless node + case parser_type(node) when 'libxml' - return el.content + return node.content when 'rexml' - return el.text + return node.text end return nil end