Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 16th, 2006, 12:27 PM
Authorized User
Join Date: May 2005
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default Extract data from the XML result of a web service

Hi - I have my fingers crossed that someone can help. I'm trying to use a webservice (http://www.webservicex.net/WS/WSDeta...TID=12&WSID=56) to get regional weather information. The problem I am having is that I don't know how to extract the data from the XML document which is returned. For example, if I get the weather in Reykjavik, Iceland using the webservice, the result returned is:

<?xml version="1.0" encoding="utf-8" ?>
  <string xmlns="http://www.webserviceX.NET"><?xml version="1.0" encoding="utf-16"?> <CurrentWeather> <Location>Reykjavik, Iceland (BIRK) 64-08N 021-54W 61M</Location> <Time>Mar 16, 2006 - 10:00 AM EST / 2006.03.16 1500 UTC</Time> <Wind> from the S (170 degrees) at 14 MPH (12 KT):0</Wind> <Visibility> greater than 7 mile(s):0</Visibility> <SkyConditions> mostly cloudy</SkyConditions> <Temperature> 48 F (9 C)</Temperature> <DewPoint> 42 F (6 C)</DewPoint> <RelativeHumidity> 81%</RelativeHumidity> <Pressure> 30.50 in. Hg (1033 hPa)</Pressure> <Status>Success</Status> </CurrentWeather></string>

The problem I am having is that the ONLY information I need is the <Temperature> and the <SkyConditions> and I don't know how to extract just these two pieces of information to display on my site.

At the moment I use the webservice inside a class. I am successfully calling the webservice (I think), however, as I said, I don't know how to just get the data that I want from the result:

Public Class Facts
  Inherits Control

  Private weather As New GlobalWeather()

  Function getWeatherCond() As String
    Dim strWeather As String
        strWeather = weather.GetWeather("Reykjavik", "Iceland")

    ...unsure from here on in....

  End Function


  Protected Overrides Sub Render(writer As HtmlTextWriter)
    writer.write(getWeatherCond("Reykjavik","Iceland") )
  End Sub
End Class

To be honest, the only way I have got it to work for me (based on my knowledge) is to use a substring to find the appropriate tag. For example, for the <Temperature> I use:

Dim intTempStart As Integer = strWeather.IndexOf("<Temperature>", intStartPoint) + 14

Although this works, I'm guessing there is a better way to do this which is more effective. I've searched Google for any information and can't find anything, so am now hoping that someone here can help. I'm not sure if it has to do with how I am calling the webservice?

Thanks so much in advance for any help - and I hope this makes sense!

Similar Threads
Thread Thread Starter Forum Replies Last Post
xml text reader from Web Service djcowbell .NET Web Services 4 June 27th, 2007 08:40 AM
how to show result of MS Analysis service to WEB? rosejeep C# 0 November 8th, 2006 09:27 PM
Extract data and create xml for input dhol General .NET 1 February 2nd, 2005 03:01 PM
How to send an xml to a web service agbeltekin General .NET 0 May 10th, 2004 09:44 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.