0

我正在尝试编写一个嵌套查询,因为我正在使用的 XML 文档有多个子元素。我需要访问 document-id 属性为“docdb”的值。我需要访问 document-id 属性为“epodoc”的值。

我的类 case_ 定义如下:

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

这是我到目前为止所拥有的:

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());
        }

我正在使用的 XML 如下:

<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>

我似乎无法得到我的查询但是带回任何结果。

4

2 回答 2

1

appDate应该对应

appDate = (from p in theCases.Descendants("document-id")
where (string)p.Attribute("document-id-type") == "epodoc"
select (p.Element("date").Value)).FirstOrDefault()
于 2013-10-09T17:01:19.443 回答
1

根据 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()

Anirudh 帖子的变化是添加了另一个函数调用:

.Descendants("document-id") 

这是必需的,因为 XML 中有多个“document-id”元素。

于 2013-10-18T14:51:55.800 回答