2011-11-17 3 views
0

내 C# 코딩에서 XML 파일의 일부 데이터를 가져 오려고합니다. 주장-IB-정보를 원하시면 다음노드가 노드를 철회 포함하지 않는 경우XML 쿼리 문제

어떻게 주장 노드의 데이터를 얻을 수 있습니다.

내가 궁금한 점이 있으면 알려주십시오.

XML에 대해 많이 알지 못하고 미리 감사드립니다.

<info> 
    <claim kind="national" sequence="1"> 
     <country>UK</country> 
     <number>66</number> 
     <date>20080602</date> 
    </claim> 
    <claim-ib-info> 
     <received-at> 
      <date>20090610</date> 
     </received-at> 
    </claim-ib-info> 


    <claim kind="national" sequence="2"> 
     <country>US</country> 
     <number>125</number> 
     <date>20080501</date> 
    </claim> 
    <claim-ib-info> 
     <withdrawn> 
      <date>20100721</date> 
     </withdrawn> 
    </claim-ib-info> 


    <claim kind="national" sequence="3"> 
     <country>TH</country> 
     <number>61</number> 
     <date>20090316</date> 
    </claim> 
    <claim-ib-info> 
     <received-at> 
      <date>20090610</date> 
     </received-at> 
    </claim-ib-info> 


    <claim kind="national" sequence="4"> 
     <country>MY</country> 
     <number>66</number> 
     <date>20090209</date> 
    </claim> 
    <claim-ib-info> 
     <withdrawn> 
      <date>20101221</date> 
     </withdrawn> 
    </claim-ib-info> 
</info> 

답변

3

봅니다 배우고 Linq to XML.

var list = from ele in XDocument.Load(@"c:\files.xml").Descendants("claim-ib-info") 
        where ele.Element("withdrawn")!=null 
        select ele.PreviousNode ; 

foreach (var t in list) 
{ 
    Console.WriteLine(t); 
}