[英]Simple Linq to XML question
鉴于以下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>
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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.