我有解析XML文件來檢索標籤名稱的問題。我有一個以下的XML文件:獲取標籤的名稱在xml
<city version="1.2" last_updated="Thu, 28 Aug 2014 12:10:38 +0300">
<city id="8750">
<name>Лондон</name>
<name_en>London</name_en>
<region/>
<country>Великобритания</country>
<country_id>826</country_id>
</city>
<city id="110254">
<name>Лондон</name>
<name_en>London</name_en>
<region/>
<country>Канада</country>
<country_id>124</country_id>
</city>
<city id="58690">
<name>Лондон</name>
<name_en>London</name_en>
<region>Arkansas</region>
<country>Соединенные Штаты Америки</country>
<country_id>840</country_id>
</city>
<city id="65450">
<name>Лондон</name>
<name_en>London</name_en>
<region>Kentucky</region>
<country>Соединенные Штаты Америки</country>
<country_id>840</country_id>
</city>
<city id="76284">
<name>Лондон</name>
<name_en>London</name_en>
<region>Ohio</region>
<country>Соединенные Штаты Америки</country>
<country_id>840</country_id>
</city>
<city id="131">
<name>Макеевка</name>
<name_en>Makiivka</name_en>
<region>Донецкая область</region>
<country>Украина</country>
<country_id>804</country_id>
</city>
</city>
我想要做的數組或選擇與標籤的所有名稱,例如國家的列表。我有以下代碼:
string filePath = String.Format("http://xml.weather.co.ua/1.2/city/?search={0}", name);
var xmlDocument = new XmlDocument();
xmlDocument.Load(filePath);
if (xmlDocument.DocumentElement != null)
foreach (XmlNode xmlNode in xmlDocument.GetElementsByTagName("city"))
yield return new SelectListItem
{
Text = xmlNode.Value,
Value = xmlNode.ToString()
};
}
如何解決此問題?任何想法?
確定。你的代碼中有什麼不起作用?有什麼異常?哪個錯誤?哪裏?意外的結果?什麼? BTW國際海事組織幾個額外的{}將有助於可讀性很多... – 2014-08-29 08:48:34
我想獲得與標記國家的所有價值,我不知道如何 – egor 2014-08-29 08:49:52
我看這裏很酷的傢伙誰坐當前minusVat可能沒有,但只能幫助 – egor 2014-08-29 08:52:49