2012-02-16 10 views
1

私はバンガロールに住んでいる人の詳細を知る必要がある XDocumentを使用してデータを解析すると結果が得られません - なぜですか?

<!--Sample Person Data--> 
<Person> 
    <PersonDetail PersonId="1"> 
    <Name>Priyanka Das</Name> 
    <Age>30</Age> 
    <Sex>Male</Sex> 
    <LivesIn>Bangalore</LivesIn> 
    <Email>[email protected]</Email> 
    </PersonDetail> 
    <PersonDetail PersonId="2"> 
    <Name>Shashidhar Nikatani</Name> 
    <Age>40</Age> 
    <Sex>Male</Sex> 
    <LivesIn>Bangalore</LivesIn> 
    <Email>[email protected]</Email> 
    </PersonDetail> 
    <PersonDetail PersonId="3"> 
    <Name>Arundhuti Roy</Name> 
    <Age>27</Age> 
    <Sex>Female</Sex> 
    <LivesIn>Kerala</LivesIn> 
    <Email>[email protected]</Email> 
    </PersonDetail> 
    <PersonDetail PersonId="4"> 
    <Name>Nitin Mallik</Name> 
    <Age>28</Age> 
    <Sex>Male</Sex> 
    <LivesIn>Bangalore</LivesIn> 
    <Email>[email protected]</Email> 
    </PersonDetail> 
    <PersonDetail PersonId="5"> 
    <Name>Essaki Raja Kandaswamy</Name> 
    <Age>27</Age> 
    <Sex>Male</Sex> 
    <LivesIn>Madras</LivesIn> 
    <Email>[email protected]</Email> 
    </PersonDetail> 
</Person> 

としてxmlファイルを持っています。

私は以下を行わなく、どんな結果に

XDocument xmlSource = null; 
    xmlSource = XDocument.Load(@"D:\Personsample.xml"); 

      var query = from data in xmlSource.Descendants("Person") 
         where (string)data.Element("LivesIn") == "Bangalore" 
         select data; 

を得ることができなかったヘルプは、「人」のは直接「LivesIn」子どもたちはとてもdata.Element("LivesIn")は必ず何かを得られません、ありません

+2

を、それは '' xmlSource.Descendantsのデータから( "PersonDetail")すべきではない:

はあなたが意味するものではありませんでしたか? –

答えて

3

を必要としていました。

from data in xmlSource.Descendants("PersonDetail") 
        where (string)data.Element("LivesIn") == "Bangalore" 
        select data; 
関連する問題