1
我有一個XML文件作爲下使用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>
我需要找出人誰住在班加羅爾的細節。
我也做了以下,但沒能獲得任何結果
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;
幫助需要
它不應該是'從數據xmlSource.Descendants( 「PersonDetail」)'? – 2012-02-16 02:47:04