473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

WebService returns XML in a String - how can I 'convert' this to an XML document?

I'm querying a web service to get some global weather data (http://www.webservicex.net/globalweather.asmx?WSDL) which works really well, however I'm getting stuck on the returned data for the GetWeather call.

The data returned is presented as a string but actually contains XML data. I'd like to treat the data as XML, and then save it to a file, append other results etc. so I can re-use the data later without having to requery the server (to save time etc.)

But I'm really new to XML and don't know where to start. I've managed to get the data into an XML with the code shown at the bottom, but I need to manipulate the XML (add some nodes, change some, delete some etc.) and I'd really like to do this before I save the file, rather than save it, then re-load it.

Is there a simple way I can just create an XML object (XMLDocument?) and just drop the contents of the string into it? Thanks.

sWeatherXML = wsNewWeather.GetWeather("Las Vegas", "United States")
Dim fs As New FileStream("Weather.xml", FileMode.OpenOrCreate)
Dim xw As New XmlTextWriter(fs, Nothing)
xw.WriteStartDocument()
xw.WriteRaw(sWeatherXML)
xw.Close()

Ben Turner
be*@guidetotheworld.net
Nov 18 '05 #1
2 2030
Ben Turner wrote:
Is there a simple way I can just create an XML object (XMLDocument?) and
just drop the contents of the string into it? Thanks.


Check out the LoadXml method of the XmlDocument class:

http://msdn.microsoft.com/library/de...adxmltopic.asp

---
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #2
Hi Ben,

An approach that I prefer in this case is to treat the everything as a
dataset and datatables. I find it easier to manipulate than XML nodes.

For example, your weather XML is quite simple in format. You can put XML
from the ws into a dataset and then add another table with your own data.
After that, just write it to the file.

The advantage is that you can read it back into a page and manipulate it as
data rather than as XML.

Here's the key part:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim wsNewWeather As New net.webservicex.www.GlobalWeather
Dim sreader As New System.IO.StringReader _
(wsNewWeather.GetWeather("Las Vegas", "United States"))
Dim ds As New DataSet
Dim dt As New DataTable
Dim dr As DataRow
' Read the XML from the ws into the dataset
ds.ReadXml(sreader)
' Give the new table a name
dt.TableName = "BenData"
' Add a couple of columns to the new table
dt.Columns.Add(New DataColumn _
("BenInteger", GetType(Int32)))
dt.Columns.Add(New DataColumn _
("BenString", GetType(String)))
' Add a row to the table
dr = dt.NewRow
' Fill the row with data
dr.Item("BenInteger") = 10
dr.Item("BenString") = "Hello"
' Add the row to the table
dt.Rows.Add(dr)
' Add the table to the dataset
ds.Tables.Add(dt)
' Write the whole dataset to the file
ds.WriteXml("c:\dsetwser.xml")
End Sub

This produces:

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
<CurrentWeather>
<Location>Las Vegas, Las Vegas Municipal Airport, NM, United States
(KLVS) 35-39-15N 105-08-33W 2091M</Location>
<Time>Jan 01, 2004 - 11:53 PM EST / 2004.01.02 0453 UTC</Time>
<Wind> from the SSE (160 degrees) at 29 MPH (25 KT):0</Wind>
<Visibility> 10 mile(s):0</Visibility>
<SkyConditions> clear</SkyConditions>
<Temperature> 39.0 F (3.9 C)</Temperature>
<DewPoint> 21.9 F (-5.6 C)</DewPoint>
<RelativeHumidity> 49%</RelativeHumidity>
<Pressure> 29.98 in. Hg (1015 hPa)</Pressure>
<Status>Success</Status>
</CurrentWeather>
<BenData>
<BenInteger>10</BenInteger>
<BenString>Hello</BenString>
</BenData>
</NewDataSet>

Does this help?

Ken
"Ben Turner" <be*@guidetotheworld.net> wrote in message
news:ig*****************@news-server.bigpond.net.au...
I'm querying a web service to get some global weather data
(http://www.webservicex.net/globalweather.asmx?WSDL) which works really
well, however I'm getting stuck on the returned data for the GetWeather
call.

The data returned is presented as a string but actually contains XML data.
I'd like to treat the data as XML, and then save it to a file, append other
results etc. so I can re-use the data later without having to requery the
server (to save time etc.)

But I'm really new to XML and don't know where to start. I've managed to
get the data into an XML with the code shown at the bottom, but I need to
manipulate the XML (add some nodes, change some, delete some etc.) and I'd
really like to do this before I save the file, rather than save it, then
re-load it.

Is there a simple way I can just create an XML object (XMLDocument?) and
just drop the contents of the string into it? Thanks.

sWeatherXML = wsNewWeather.GetWeather("Las Vegas", "United States")
Dim fs As New FileStream("Weather.xml", FileMode.OpenOrCreate)
Dim xw As New XmlTextWriter(fs, Nothing)
xw.WriteStartDocument()
xw.WriteRaw(sWeatherXML)
xw.Close()

Ben Turner
be*@guidetotheworld.net

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JohnSmith | last post by:
Hi, I'm consuming a webservice which returns an XMLNode with VB.NET and XSLT and sending the output to Response.OutputStream If I feed the returned XMLNode directly in the transform method, I...
7
by: stephan querengaesser | last post by:
hi ng, i try to invoke a webservice-method with an filter-object, that contains value types. if i donīt want to filter the return value of the method, i have to pass a new instance of the...
5
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
9
by: Nick Gilbert | last post by:
Hi, I'm trying to create a system whereby my desktop application submits it's order to an online server using a webservice (pretty standard!). So, I added a new project to my solution to...
7
by: Nalaka | last post by:
Hi, I created a sinple web service that returns a dataSet. Then I created a client program that uses this web service (that returns the Dataset). My question is, how did the client figure...
5
by: needin4mation | last post by:
Hi, I have a webservice that just returns a count: public DataSet HelloWorld() { OdbcConnection conn = new OdbcConnection("DSN=xxx"); String sqlString = "select count(*) as employee from...
1
by: jdhavo | last post by:
I'm trying to download an image file using XML from a web service. When the dialog box appears asking if I want to save the document or open it, If I click save and then open it, it works fine. If...
1
by: Pim75 | last post by:
Hello, I've written a webservice that returns an array. The output of the webservice has to be consumed by a classic asp application. As classic asp can't read the returned array I want the...
6
by: Peter | last post by:
I have a WebService which returns a List of RunningReport class How do I read this XML data on the client side. How do I convert List<RunningReportfrom the WebService side to List<RunningReporton...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.