簡體   English   中英

簡單的Linq to XML問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM