如何在我的XML
文件中选择特定节点?阅读特定XML节点
在我的第一foreach
我选择每Property
是我Properties
标签里面,但我希望有一个特定的Property
。例如,具有<PropertyCode>
的等于123。
XML
<Carga>
<Properties>
<Property>
<PropertyCode>122</PropertyCode>
<Fotos>
<Foto>
</Foto>
</Fotos>
</Property>
<Property>
<PropertyCode>123</PropertyCode>
<Fotos>
<Foto>
</Foto>
</Fotos>
</Property>
</Properties>
</Carga>
C#代码
// Here I get all Property tag
// But i want to take just a specific one
foreach (XmlElement property in xmldoc.SelectNodes("/Carga/Properties/Property"))
{
foreach (XmlElement photo in imovel.SelectNodes("Fotos/Foto"))
{
string photoName = photo.ChildNodes.Item(0).InnerText.Trim();
string url = photo.ChildNodes.Item(1).InnerText.Trim();
this.DownloadImages(property_id, url, photoName);
}
}
有人能帮助我吗?
用'XMLDocument'能我这样做? –
@Lucas_Santos你可以,但你为什么? Linq to Xml给你很好的强类型解析 –
在第一时刻,我想用'XMLDocument'来工作,因为我的XML文件比我放的这个样本大得多。所以,当我更新我的应用程序的版本时,我可以更改为'XDocument' –