Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何在VB.net中用分号解析特定元素_Xml_Vb.net - Fatal编程技术网

Xml 如何在VB.net中用分号解析特定元素

Xml 如何在VB.net中用分号解析特定元素,xml,vb.net,Xml,Vb.net,我试图解析和中的值,并将这些值存储在以下XML文件中的两个变量lat和longi中 <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"> <channel> <title>Yahoo! Weather - Accrington, GB<

我试图解析
中的值,并将这些值存储在以下XML文件中的两个变量lat和longi中

<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">
    <channel>
    <title>Yahoo! Weather - Accrington, GB</title>
    <link>
    http://us.rd.yahoo.com/dailynews/rss/weather/Accrington__GB/*http://weather.yahoo.com/forecast/UKXX1241_c.html
    </link>
    <description>Yahoo! Weather for Accrington, GB</description>
    <language>en-us</language>
    <lastBuildDate>Fri, 12 Sep 2014 4:50 pm BST</lastBuildDate>
    <ttl>60</ttl>
    <yweather:location city="Accrington" region="" country="United Kingdom"/>
    <yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
    <yweather:wind chill="18" direction="140" speed="8.05"/>
    <yweather:atmosphere humidity="59" visibility="9.99" pressure="1015.92" rising="0"/>
    <yweather:astronomy sunrise="6:37 am" sunset="7:34 pm"/>
    <image>
    <title>Yahoo! Weather</title>
    <width>142</width>
    <height>18</height>
    <link>http://weather.yahoo.com</link>
    <url>
    http://l.yimg.com/a/i/brand/purplelogo//uh/us/news-wea.gif
    </url>
    </image>
    <item>
    <title>Conditions for Accrington, GB at 4:50 pm BST</title>
    <geo:lat>53.75</geo:lat>
    <geo:long>-2.37</geo:long>
    <link>
    http://us.rd.yahoo.com/dailynews/rss/weather/Accrington__GB/*http://weather.yahoo.com/forecast/UKXX1241_c.html
    </link>
    <pubDate>Fri, 12 Sep 2014 4:50 pm BST</pubDate>
    <yweather:condition text="Mostly Cloudy" code="28" temp="18" date="Fri, 12 Sep 2014 4:50 pm BST"/>
    <description>
    <![CDATA[
    <img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br /> <b>Current Conditions:</b><br /> Mostly Cloudy, 18 C<BR /> <BR /><b>Forecast:</b><BR /> Fri - Partly Cloudy. High: 18 Low: 9<br /> Sat - Partly Cloudy. High: 20 Low: 9<br /> Sun - Cloudy. High: 20 Low: 11<br /> Mon - PM Showers. High: 18 Low: 13<br /> Tue - Showers. High: 19 Low: 12<br /> <br /> <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Accrington__GB/*http://weather.yahoo.com/forecast/UKXX1241_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/> (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
    ]]>
    </description>
    <yweather:forecast day="Fri" date="12 Sep 2014" low="9" high="18" text="Partly Cloudy" code="29"/>
    <yweather:forecast day="Sat" date="13 Sep 2014" low="9" high="20" text="Partly Cloudy" code="30"/>
    <yweather:forecast day="Sun" date="14 Sep 2014" low="11" high="20" text="Cloudy" code="26"/>
    <yweather:forecast day="Mon" date="15 Sep 2014" low="13" high="18" text="PM Showers" code="39"/>
    <yweather:forecast day="Tue" date="16 Sep 2014" low="12" high="19" text="Showers" code="11"/>
    <guid isPermaLink="false">UKXX1241_2014_09_16_7_00_BST</guid>
    </item>
    </channel>
    </rss>
    <!--
     api15.weather.bf1.yahoo.com Fri Sep 12 14:39:57 PDT 2014 
    -->
在此方面的任何帮助都将不胜感激

谢谢
Boyercam

分号之前的部分是名称空间前缀,在您的例子中,它在根元素处声明。您需要将前缀到命名空间URI映射注册到
XmlNamespaceManager
,并在XPath中使用注册的前缀,例如:

Dim doc As XmlDocument = New XmlDocument()
......
......
Dim nsManager As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
nsManager.AddNamespace("geo", "http://www.w3.org/2003/01/geo/wgs84_pos#")
lat = nodes.Item(0).SelectSingleNode(".//geo:lat", nsManager).InnerText

你的第一句话出了问题。请编辑它。请告诉我们您会遇到什么样的错误。
Dim doc As XmlDocument = New XmlDocument()
......
......
Dim nsManager As XmlNamespaceManager = New XmlNamespaceManager(doc.NameTable)
nsManager.AddNamespace("geo", "http://www.w3.org/2003/01/geo/wgs84_pos#")
lat = nodes.Item(0).SelectSingleNode(".//geo:lat", nsManager).InnerText