Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
简单的Linq到XML问题_Xml_Linq_Linq To Xml - Fatal编程技术网

简单的Linq到XML问题

简单的Linq到XML问题,xml,linq,linq-to-xml,Xml,Linq,Linq To Xml,给定下面的XML 假设我有两个变量“Idnt”和“Xref”,它们将存储#ID。。如何获得这些值 我想要 var Idnt = 5169452 and var xref = 5169452 <ecf:EntityPerson xmlns:ecf="xx"> <nc:PersonName xmlns:nc="xx"> <nc:PersonGivenName>JAMES</nc:PersonGivenName> <n

给定下面的XML

假设我有两个变量“Idnt”和“Xref”,它们将存储#ID。。如何获得这些值

我想要

var Idnt = 5169452
and
var xref = 5169452




 <ecf:EntityPerson xmlns:ecf="xx">
  <nc:PersonName xmlns:nc="xx">
    <nc:PersonGivenName>JAMES</nc:PersonGivenName>
    <nc:PersonMiddleName>TIBERIUS</nc:PersonMiddleName>
    <nc:PersonSurName>KIRK</nc:PersonSurName>
  </nc:PersonName>
  <nc:PersonOtherIdentification xmlns:nc="xx">
    <nc:IdentificationID>5169452</nc:IdentificationID>
    <nc:IdentificationCategoryText>IDNT</nc:IdentificationCategoryText>
  </nc:PersonOtherIdentification>
  <nc:PersonOtherIdentification xmlns:nc="xx">
    <nc:IdentificationID>5169452</nc:IdentificationID>
    <nc:IdentificationCategoryText>XREF</nc:IdentificationCategoryText>
  </nc:PersonOtherIdentification>
</ecf:EntityPerson>
var Idnt=5169452
和
变量外部参照=5169452
詹姆斯
提比略
柯克
5169452
IDNT
5169452
外部参照
XNamespace ns = "xx";

var doc = XDocument.Load(xmlFilePath);
int idnt =
    int.Parse(
        doc.Descendants(ns + "PersonOtherIdentification")
        .Where(e => e.Element(ns + "IdentificationCategoryText").Value == "IDNT")
        .Single().Element(ns + "IdentificationID").Value);

Console.WriteLine(idnt);