Getting an error. XML code
Getting an error. XML code
Getting an error. XML code
Getting an error. XML code
Getting an error. XML code
Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code
Getting an error. XML code Getting an error. XML code
Getting an error. XML code
Go Back  Xtreme Visual Basic Talk > > > Getting an error. XML code


Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2014, 02:25 PM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default Getting an error. XML code


It's a program to access a weather web service, fetch the XML data then try to extract certain info from it.

The line causing the error is:
Quote:
txtTime.Text = CStr(xmlWeather.InnerText)
The error is:
Quote:
Object reference not set to an instance of an object.
Code:
Public Class frmWeather

    Private Sub btnGet_Click(sender As System.Object, e As System.EventArgs) Handles btnGet.Click
        Dim service As New ServiceReferenceGlobalWeather.GlobalWeatherSoapClient("GlobalWeatherSoap")
        Dim serviceReturn As String
        Dim cityName As String

        Try
            lstCities.Items.Clear()
            serviceReturn = service.GetCitiesByCountry(txtCountry.Text)
            MessageBox.Show(serviceReturn)
            Dim xmlCities As New Xml.XmlDocument
            xmlCities.LoadXml(serviceReturn)
            Dim xmlCity As Xml.XmlNode

            For Each xmlCity In xmlCities.DocumentElement.ChildNodes
                cityName = xmlCity.LastChild.InnerText
                lstCities.Items.Add(cityName)
                'MessageBox.Show(cityName)
            Next

            Dim xmlWeather As New System.Xml.XmlDocument
            xmlWeather.LoadXml(serviceReturn)
            cityName = (xmlCities.SelectSingleNode("//City").InnerText) ' Get first city
            serviceReturn = service.GetWeather(cityName, txtCountry.Text)
            MessageBox.Show(serviceReturn)

            txtTime.Text = CStr(xmlWeather.SelectSingleNode("//Time").InnerText)' ***this line causes error***

        Catch ex As Exception
            MessageBox.Show("error")
        End Try

    End Sub

End Class
If it helps here is the XML which will be fed into xmlWeather. I want to extract the info between the "Time" tags and display in a text box.

http://s17.postimg.org/py6452itr/xml.jpg
Reply With Quote
  #2  
Old 10-06-2014, 04:48 PM
PlausiblyDamp's Avatar
PlausiblyDampGetting an error. XML code PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Is this a publicly accessible service or a private one? Does the service not return strongly typed results from the methods, only XML?

If you set a breakpoint and step through the code what does the debugger show as being the contents of xmlWeather before the line that causes the crash? If you try to get the result of xmlWeather.SelectSingleNode("//Time") into a variable before getting the .InnerText what happens?

Is there a reason you are using //Time rather than /CurrentWeather/Time to select the node?
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #3  
Old 10-06-2014, 05:27 PM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default

It's a public service: http://www.webservicex.net/globalweather.asmx?wsdl

Trying "/CurrentWeather/Time" instead makes no difference.

I got the result of xmlWeather.SelectSingleNode("//Time") into a variable, but the variable was zero in length.
Reply With Quote
  #4  
Old 10-07-2014, 05:31 AM
PlausiblyDamp's Avatar
PlausiblyDampGetting an error. XML code PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Just tried to access the service and for some reason it does seem to return raw XML rather than a structured result, sort of defeating the point of a web service really....

That said when I ran the code and used the debugger to output the contents of the xmlWeather variable the XML I had back looked like
Code:
<NewDataSet>
<Table><Country>Ukraine</Country><City>Boryspil</City></Table><Table><Country>Ukraine</Country><City>Simferopol</City></Table><Table><Country>Ukraine</Country><City>Kharkiv</City></Table><Table><Country>Ukraine</Country><City>Kyiv</City></Table><Table><Country>Ukraine</Country><City>L'Viv</City></Table><Table><Country>Ukraine</Country><City>Odesa</City></Table>
</NewDataSet>
Which is a completely different structure to what you seem to be expecting...
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #5  
Old 10-10-2014, 03:25 PM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default

I don't know how, but I got it working.

One last thing I have to do is "Write a simple test call to GetCitiesByCountry to
retrieve the list of countries
". I'm assuming that means list all the valid countries it can accept.

So far I know how to extract data telling it what the country and city are but don't know how to get it to list all valid countries.
Reply With Quote
  #6  
Old 10-11-2014, 11:39 AM
PlausiblyDamp's Avatar
PlausiblyDampGetting an error. XML code PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

I am assuming that means you just need to call the function for a given country and show what cities are returned.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
  #7  
Old 10-12-2014, 08:46 AM
VisualaBasikka VisualaBasikka is offline
Centurion
 
Join Date: Oct 2004
Posts: 130
Default

I can already do that but the way it's worded I thought it meant retrieve a list of countries (not cities)
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Getting an error. XML code
Getting an error. XML code
Getting an error. XML code Getting an error. XML code
Getting an error. XML code
Getting an error. XML code
Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code Getting an error. XML code
Getting an error. XML code
Getting an error. XML code
 
Getting an error. XML code
Getting an error. XML code
 
-->