Note that there are some explanatory texts on larger screens.

plurals
  1. PO.net 2.0 c# retrieving a value from xml
    text
    copied!<p>I realize this is a repost but I needed to as I can't use LINQ, ( requested in my previous post). </p> <p>I need to read the woeid from the XML doc below. I need to read and store the data into a string variable so I can query the yahoo weather service.</p> <p>XML returned by query:</p> <pre><code>&lt;query yahoo:count="1" yahoo:created="2009-12-22T08:30:31Z" yahoo:lang="en-US" yahoo:updated="2009-12-22T08:30:31Z" yahoo:uri="http://query.yahooapis.com/v1/yql?q=select+woeid+from+geo.places+where+text%3D%22farnborough%2C+greater+london%2Cuk%22"&gt; &lt;diagnostics&gt; &lt;publiclyCallable&gt;true&lt;/publiclyCallable&gt; &lt;url execution-time="32"&gt; http://where.yahooapis.com/v1/places.q(farnborough%2C%20greater%20london%2Cuk);start=0;count=10 &lt;/url&gt; &lt;user-time&gt;33&lt;/user-time&gt; &lt;service-time&gt;32&lt;/service-time&gt; &lt;build-version&gt;4265&lt;/build-version&gt; &lt;/diagnostics&gt; &lt;results&gt; &lt;place&gt; &lt;woeid&gt;19941&lt;/woeid&gt; &lt;/place&gt; &lt;/results&gt; &lt;/query&gt; </code></pre> <p>Can someone suggest how I could do this through XPath or another way which is compatible with the libraries in .net 2.0?</p> <p>Thanks for the answers. As such I am using the method below, but I get an exception thrown when loading the XML document:</p> <pre><code>private string getWOEID(string UserLocation, string UserCountry) { string woeID = ""; if (UserLocation == "farnborough") { UserLocation = "farnborough" + "%2C" + "hampshire"; } String reqUrl = "http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22" + UserLocation + "%2C" + UserCountry + "%22&amp;format=xml"; XmlDocument doc = new XmlDocument(); doc.LoadXml(reqUrl); string woeid = doc.SelectSingleNode("query/results/place/woeid/text()").Value; return woeID; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload