0

I am trying to write a nested query as the XML document I am working with has multiple child elements. I need to access the value where the document-id attribute is “docdb”. I need to access the value where the document-id attribute is “epodoc”.

My class case_ is defined as follows:

public class case_
{
public string appNumber { get; set; }
public string appDate { get; set; }
}

Here is what I have so far:

var myCase = from theCases in allCasesXML.Descendants("exchange-document")
select new case_
{
appNumber = (string)theCases.Element("bibliographic-data").Element("application-reference").Element("document-id").Element("doc-number"),
appDate = (from p in theCases.Descendants("document-id")
where (string)theCases.Element("bibliographic-data").Element("application-reference").Element("document-id").Attribute("document-id-type") == "epodoc"
select (p.Element("date").Value)),

  };

        foreach (var case_ in myCase)
        {
            System.Windows.Forms.MessageBox.Show(case_.appDate.ToString());
        }

The XML I am working with is as follows:

<exchange-document system="ops.epo.org" family-id="8487663" country="EP" doc- number="0173444" kind="A1">
<bibliographic-data>
<publication-reference>
  <document-id document-id-type="docdb">
    <country>EP</country>
    <doc-number>0173444</doc-number>
    <kind>A1</kind>
    <date>19860305</date>
  </document-id>
  <document-id document-id-type="epodoc">
    <doc-number>EP0173444</doc-number>
    <date>19860305</date>
  </document-id>
</publication-reference>
<classification-ipc>
  <text>B27M3/06</text>
</classification-ipc>
<classifications-ipcr>
  <classification-ipcr sequence="1">
    <text>B27M   1/    04            A I                    </text>
  </classification-ipcr>
  <classification-ipcr sequence="2">
    <text>B27M   3/    04            A I                    </text>
  </classification-ipcr>
  <classification-ipcr sequence="3">
    <text>B44C   3/    12            A I                    </text>
  </classification-ipcr>
</classifications-ipcr>
<patent-classifications>
  <patent-classification sequence="1">
    <classification-scheme office="" scheme="CPC" />
    <section>B</section>
    <class>44</class>
    <subclass>C</subclass>
    <main-group>3</main-group>
    <subgroup>12</subgroup>
    <classification-value>I</classification-value>
  </patent-classification>
  <patent-classification sequence="2">
    <classification-scheme office="" scheme="CPC" />
    <section>B</section>
    <class>27</class>
    <subclass>M</subclass>
    <main-group>1</main-group>
    <subgroup>04</subgroup>
    <classification-value>I</classification-value>
  </patent-classification>
  <patent-classification sequence="3">
    <classification-scheme office="" scheme="CPC" />
    <section>B</section>
    <class>27</class>
    <subclass>M</subclass>
    <main-group>3</main-group>
    <subgroup>04</subgroup>
    <classification-value>I</classification-value>
  </patent-classification>
</patent-classifications>
<application-reference doc-id="16601238">
  <document-id document-id-type="docdb">
    <country>EP</country>
    <doc-number>85305178</doc-number>
    <kind>A</kind>
  </document-id>
  <document-id document-id-type="epodoc">
    <doc-number>EP19850305178</doc-number>
    <date>19850719</date>
  </document-id>
  <document-id document-id-type="original">
    <doc-number>85305178</doc-number>
  </document-id>
</application-reference>

I can't seem to get my query however to bring back any results.

2 Answers 2

1

appDate should correspond to

appDate = (from p in theCases.Descendants("document-id")
where (string)p.Attribute("document-id-type") == "epodoc"
select (p.Element("date").Value)).FirstOrDefault()
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that. I changed it slightly: appDate = (from p in theCases.Descendants("application-reference").Descendants("document-id") where (string)p.Attribute("document-id-type") == "epodoc" select (p.Element("date").Value)).FirstOrDefault()
1

Based on the post by Anirudh:

appDate = (from p in theCases.Descendants("application-reference").Descendants("document-  id") 
where (string)p.Attribute("document-id-type") == "epodoc" 
select (p.Element("date").Value)).FirstOrDefault()

The change from the post by Anirudh is the addition of another call of the function:

.Descendants("document-id") 

This is required as there are multiple "document-id" elements in the XML.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.