简单的Linq到XML问题
给定下面的XML 假设我有两个变量“Idnt”和“Xref”,它们将存储#ID。。如何获得这些值 我想要简单的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
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);