1

I am getting an XML from a OAI-PMH request which contains a resumption token to get next set of records. How to get the resumption token Value and its other attributes such as completeListSize etc.

 <?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="static/style.xsl"?><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>2015-06-24T16:45:25Z</responseDate>
<request verb="ListRecords" metadataPrefix="uketd_dc">http://publications.iadb.org/oai/request</request>
<ListRecords>
    <record>
        <header>
            <identifier>oai:publications.iadb.org:11319/195</identifier>
            <datestamp>2015-06-12T23:02:48Z</datestamp>
            <setSpec>com_123456789_1</setSpec>
            <setSpec>col_123456789_3</setSpec>
        </header>
        <metadata></metadata>
    </record>  
 <resumptionToken completeListSize="6305" cursor="0">MToxMDB8Mjp8Mzp8NDp8NTp1a2V0ZF9kYw==</resumptionToken>
</ListRecords>

I tried the below code

 XDocument root= XDocument .Load("http://publications.iadb.org/oai/request?verb=ListRecords&metadataPrefix=uketd_dc");
        var tokenValue= root.Element("resumptionToken").Value;

Its returning object reference error.Please help.

1 Answer 1

1

Element returns an immediate child element. From the context of your document, the only element available to you is OAI-PMH - this is why you're getting the null reference exception.

In addition, your target element has a namespace as defined by the default namespace declaration (xmlns="...") in the root OAI-PMH element.

You can use Descendants to find any element in the document with your required name, so this short code should work:

XNamespace ns = "http://www.openarchives.org/OAI/2.0/";
var tokenValue = (string)root.Descendants(ns + "resumptionToken").Single();
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.