473,657 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Ge tWeather("Las Vegas", "United States")
Dim fs As New FileStream("Wea ther.xml", FileMode.OpenOr Create)
Dim xw As New XmlTextWriter(f s, Nothing)
xw.WriteStartDo cument()
xw.WriteRaw(sWe atherXML)
xw.Close()

Ben Turner
be*@guidetothew orld.net
Nov 18 '05 #1
2 2044
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.EventArg s) _
Handles MyBase.Load
Dim wsNewWeather As New net.webservicex .www.GlobalWeather
Dim sreader As New System.IO.Strin gReader _
(wsNewWeather.G etWeather("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(srea der)
' 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("BenInt eger") = 10
dr.Item("BenStr ing") = "Hello"
' Add the row to the table
dt.Rows.Add(dr)
' Add the table to the dataset
ds.Tables.Add(d t)
' 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>
<SkyCondition s> clear</SkyConditions>
<Temperature> 39.0 F (3.9 C)</Temperature>
<DewPoint> 21.9 F (-5.6 C)</DewPoint>
<RelativeHumidi ty> 49%</RelativeHumidit y>
<Pressure> 29.98 in. Hg (1015 hPa)</Pressure>
<Status>Success </Status>
</CurrentWeather>
<BenData>
<BenInteger>1 0</BenInteger>
<BenString>Hell o</BenString>
</BenData>
</NewDataSet>

Does this help?

Ken
"Ben Turner" <be*@guidetothe world.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.Ge tWeather("Las Vegas", "United States")
Dim fs As New FileStream("Wea ther.xml", FileMode.OpenOr Create)
Dim xw As New XmlTextWriter(f s, Nothing)
xw.WriteStartDo cument()
xw.WriteRaw(sWe atherXML)
xw.Close()

Ben Turner
be*@guidetothew orld.net

Nov 18 '05 #3

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

Similar topics

0
1308
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 get an error: System.InvalidOperationException: The specified node cannot be inserted as the valid child of this node, because the specified node is the wrong type.
7
5393
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 filter-object without setting any properties. but the value type-properties can´t be null and the filter is set to 0 (int) or false (bool). therefore i did implement the propertySpecified-pattern like this:
5
6908
by: mtv | last post by:
Hi all, I have the following code: ================================ Webservice side: public class MyWS: WebService { private myLib.DataObject curDataObject;
9
2676
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 develop the webservice in and created a basic webservice which just returns my "Order" object as a string. I then added some code to my app to call my webservice and pass it an
7
2917
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 out to create a "DataSet" as the return type from the webservice?
5
6840
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 employees"; DataSet myResults = new DataSet(); OdbcDataAdapter myAdapter = new OdbcAdapter(sqlString, conn); myAdapter.Fill(myResults); return myResults;
1
1797
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 I click open, I get an error that the header is not recognized. Node 3 contains the binary document returned from the Doc_Qanda_rev.exe. Here is my code: ASPX Module: sXML = pdmWS.GetBinaryDoc(ErrorCode, ErrorMsg, e.Item.Cells(5).Text.Trim,...
1
1534
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 webservice to return a xml document instead of the array. Can anyone tell me how I can output the array as a xml document?
6
2980
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 the client side I have tried the following: List<RunningReportreportList = null; localhost.ReportService localrs = new localhost.ReportService();
0
8421
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.