Thursday, March 6, 2008

XPath to find an attribute value (2)

I wanted to find the first occurrence of 'yweather:forecast' node and then find the value of the 'low' attribute. Here is how I got it:

Dim dom As XmlDocument = New XmlDocument


Dim lowTempPath As String = "/rss/channel/item/*[local-name()='forecast']/@low"

Dim lowTemp As String = dom.SelectSingleNode(lowTempPath).InnerText

local-name function:

The local-name function returns the name of the XML element in the local context. Therefore, if an XML element has a namespace prefix, it’s considered to be within that namespace. Using local-name removes the namespace prefix and returns the raw element name.

Professional BizTalk Server 2006

blog comments powered by Disqus