0

I am trying to get

<dc:identifier xsi:type="dcterms:URI" >bitstream link</dc:identifier>

and dc:title,publisher etc using C# in my MVC app need help as i am new to xml

<metadata>
  <uketd_dc:uketddc
         xmlns:uketd_dc="http://naca.central.cranfield.ac.uk/ethos-oai/2.0/"
         xmlns:doc="http://www.lyncode.com/xoai"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:uketdterms="http://naca.central.cranfield.ac.uk/ethos-oai/terms/" 
         xmlns:dcterms="http://purl.org/dc/terms/"
         xmlns:dc="http://purl.org/dc/elements/1.1/"
         xsi:schemaLocation="http://naca.central.cranfield.ac.uk/ethos-oai/2.0/ http://naca.central.cranfield.ac.uk/ethos-oai/2.0/uketd_dc.xsd">
    <dc:date>2010-10-14T17:31:59Z</dc:date>
    <dc:date>2010-10-14T17:31:59Z</dc:date>
    <dc:date>2003-01-01</dc:date>
    <dc:date>2015-06-12T10:34:09Z</dc:date>
    <dcterms:issued>2003-01-01</dcterms:issued>
    <dcterms:isReferencedBy xsi:type="dcterms:URI">http://www.iadb.org/en/publications/publication-detail,7101.html?id=4486</dcterms:isReferencedBy>
    <dcterms:abstract>This book looks at the key issues and lessons that policymakers must consider in designing an adequate framework for dealing with financial crises. These include structural problems and their causes, policy actions, the role of market discipline, and preemptive strategies.</dcterms:abstract>
    <dc:title>Financial Crises in Japan and Latin America</dc:title>
    <dc:creator>Zahler, Roberto</dc:creator>
    <dc:contributor>VICTORCO</dc:contributor>
    <dc:subject>Financial Crises &amp; Economic Stabilization</dc:subject>
    <dc:description>This book looks at the key issues and lessons that policymakers must consider in designing an adequate framework for dealing with financial crises. These include structural problems and their causes, policy actions, the role of market discipline, and preemptive strategies.</dc:description>
    <dc:type>Books</dc:type>
    <dc:identifier>International Lending and Debt Problems</dc:identifier>
    <dc:identifier>International Lending and Debt Problems</dc:identifier>
    <dc:identifier>International Lending and Debt Problems</dc:identifier>
    <dc:identifier>International Lending and Debt Problems</dc:identifier>
    <dc:identifier>International Lending and Debt Problems</dc:identifier>
    <dc:identifier>9781931003476</dc:identifier>
    <dc:identifier>http://www.iadb.org/en/publications/publication-detail,7101.html?id=4486</dc:identifier>
    <dc:language>en</dc:language>
    <dc:publisher>Inter-American Development Bank (IDB)</dc:publisher>
    <dc:identifier xsi:type="dcterms:URI">http://publications.iadb.org/bitstream/handle/11319/195/Financial+Crises+in+Japan+and+Latin+America.pdf?sequence=1</dc:identifier>
    <uketdterms:checksum xsi:type="uketdterms:MD5">83c42636d27d253499be4db09db02312</uketdterms:checksum>
    <dc:identifier xsi:type="dcterms:URI">http://publications.iadb.org/bitstream/handle/11319/195/Financial+Crises+in+Japan+and+Latin+America.pdf.png?sequence=11</dc:identifier>
    <uketdterms:checksum xsi:type="uketdterms:MD5">4d4c1c29a730054db0cfcfc477333626</uketdterms:checksum>
    <dc:identifier xsi:type="dcterms:URI">http://publications.iadb.org/bitstream/handle/11319/195/Financial+Crises+in+Japan+and+Latin+America.pdf.jpg?sequence=5</dc:identifier>
    <uketdterms:checksum xsi:type="uketdterms:MD5">7e49ce2e1c21c12e141aa50402037b25</uketdterms:checksum>
    <dc:identifier xsi:type="dcterms:URI">http://publications.iadb.org/bitstream/handle/11319/195/Financial+Crises+in+Japan+and+Latin+America.pdf.txt?sequence=10</dc:identifier>
    <uketdterms:checksum xsi:type="uketdterms:MD5">bad0c21c28fc8a9946bdfa5eae2bf59d</uketdterms:checksum>
  </uketd_dc:uketddc>
</metadata>

I tried the below code and not able to get the details

XDocument billingData = XDocument.Load("http://publications.iadb.org/oai/request?verb=ListRecords&metadataPrefix=uketd_dc");
XNamespace oai_dc = XNamespace.Get("http://naca.central.cranfield.ac.uk/ethos-oai/2.0/");
XNamespace oai_dc1 = XNamespace.Get("http://naca.central.cranfield.ac.uk/ethos-oai/2.0/ http://naca.central.cranfield.ac.uk/ethos-oai/2.0/uketd_dc.xsd");
XNamespace dc = XNamespace.Get("http://purl.org/dc/elements/1.1/");

var billings = from billing in billingData.Descendants(oai_dc + "uketd_dc").Descendants(oai_dc1 + "dc")
               select new Billing(billing.Element(dc + "title").Value, billing.Element(dc + "creator").Value,
                       billing.Element(dc + "description").Value, billing.Element(dc + "identifier").Value);
allBillings.AddRange(billings.ToList<Billing>());

I don't know whether i am doing correct.

Tim
  • 28,212
  • 8
  • 63
  • 76
  • I have posted the code which i tried on top..please check – salman rathore Jun 25 '15 at 15:41
  • "*and not able to get the details*" Why? You get an error? Wrong result? Which exactly? By the way, that would help us to help you if you posted clear and well indented code. – Florent Georges Jun 25 '15 at 15:43
  • From the above given xml i am trying to get the title, contributor, publisher and identifier which contains the .pdf link..On the trying the above code it shows enumeration yielded no results. how can i get these things from the above xml.. – salman rathore Jun 25 '15 at 16:27

1 Answers1

1

Your query is looking for descendants with the element local names of uketd_dc and then dc. You don't have any elements with those names - these seem to be namespace prefixes. Also, I'm not sure what your oai_dc1 namespace is supposed to be.

What you probably want is this:

XNamespace uketd_dc = "http://naca.central.cranfield.ac.uk/ethos-oai/2.0/";
XNamespace dc = "http://purl.org/dc/elements/1.1/";

var billings = from e in doc.Descendants(uketd_dc + "uketddc")
               select new Billing(
                    (string)e.Element(dc + "title"),
                    (string)e.Element(dc + "creator"),
                    (string)e.Element(dc + "description"),
                    (string)e.Element(dc + "identifier")
                    ); 

Note that your XML has multiple elements for some of these (e.g. identifier). This will return the first one.

Charles Mager
  • 25,735
  • 2
  • 35
  • 45
  • One more doubt actually i am getting the xml from a OAI-PMH it actually consists of 1000 records but i am only getting 100 records from the code below XDocument billingData2 = XDocument.Load("http://repository.iadb.org/oai/request?verb=ListRecords&metadataPrefix=oai_dc"); Can i get all records in one request. – salman rathore Jun 25 '15 at 17:36
  • It will get all of them. If it's only returning 100, then there are only 100 in the source. I would point out that there are 100 in the XML returned by the link in your question. The link in your comment is different and returns different XML with different namespaces - there are only 87 records in that. – Charles Mager Jun 25 '15 at 17:48
  • XDocument billingData = XDocument.Load("http://publications.iadb.org/oai/request?verb=ListRecords&metadataPrefix=uketd_dc"); In the end of xml it shows something like this MToxMDB8Mjp8Mzp8NDp8NTp1a2V0ZF9kYw== But on accessing link directly it shows total of 6306 records... – salman rathore Jun 26 '15 at 09:32
  • As above xml has multiple elements for some of these (e.g. identifier).How to retrieve the identifier which has a link to pdf and png International Lending and Debt Problemshttp://publications.iadb.org/bitstream/handle/11319/195/Financial+Crises+in+Japan+and+Latin+America.pdf?sequence=1 http://publications.iadb.org/bitstream/handle/11319/195/Financial+Crises+in+Japan+and+Latin+America.pdf.png?sequence=11 – salman rathore Jun 26 '15 at 09:55
  • You'd have to find some way of identifying those and filter the identifer elements using `Where`. I can't see how you can tell if it's png or pdf based on the uri. – Charles Mager Jun 26 '15 at 11:26
  • XDocument billingData = XDocument.Load("publications.iadb.org/oai/…); The above code returns only 100 records. In the end of xml it shows something like this MToxMDB8Mjp8Mzp8NDp8NTp1a2V0ZF9kYw== .But on accessing link directly it shows total of 6306 records... How to acces the full records – salman rathore Jun 26 '15 at 15:34
  • Ask the people who provide the API? – Charles Mager Jun 26 '15 at 15:35