1
第二篇帖子今天第一次被回答後,我遇到了另一個問題!XML和「:」問題
基本上我有下面的代碼。我知道除了一件事情之外它是正確的,「:」字符是不允許的並拋出一個異常,有沒有人知道解決這個問題的最好方法?
location = resultElements.Element("channel").Element("yweather:location").Attribute("city").Value
感謝
第二篇帖子今天第一次被回答後,我遇到了另一個問題!XML和「:」問題
基本上我有下面的代碼。我知道除了一件事情之外它是正確的,「:」字符是不允許的並拋出一個異常,有沒有人知道解決這個問題的最好方法?
location = resultElements.Element("channel").Element("yweather:location").Attribute("city").Value
感謝
我以爲你有完全一樣的XML輸入作爲your previous question描述。
在第一個元素有兩種命名空間中聲明:
<rss xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0"
xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
version="2.0">
你必須首先聲明XNamespace
例如他們:
Dim yweather = XNamespace.Get("http://xml.weather.yahoo.com/ns/rss/1.0")
而且你當你查詢的元素使用該命名空間以<yweather:
或<geo:
開頭。因此,請使用yweather + "location"
代替yweather:location
:
Dim location = resultElements.Element("channel") _
.Element(yweather + "location") _
.Attribute("city") _
.Value
你又一次保存了一天,非常感謝 –
請顯示您的XML。 'yweather'是一個命名空間,所以你必須在你的查詢中使用'XNamespace'實例。但是,如果沒有您試圖從中查詢數據的XML,我無法向您顯示答案。 – MarcinJuraszek