473,396 Members | 1,789 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,396 software developers and data experts.

Read Xml data

I am having a problem reading an Xml file and loading it into a dataset in
VB.net (ASP).

I seem to be able to load the remote file from the Url but once in memory I
cant manage to load it in to a dataset.

The readXml appears to want to read a file rather than a variable and I'm
not sure how to get around this issue.

I've tried loading to a file stream and converting the strFile to an
XmlDocument but this doesn't appear to get me any further.

I known the code at the bottom doesn't work I have listed it to put over the
idea of what I am trying to do.

Martyn Fewtrell
mf*******@networkclub.co.uk

--------------------------------------------
'get data

Dim Url As String = "http://www.url/file.xml"

Dim Request As HttpWebRequest

Dim Response As WebResponse

Dim strFile As String

Try

Request = CType(WebRequest.Create(Url), HttpWebRequest)

Response = Request.GetResponse()

litError1.Text = "Response Recieved"

Catch ex As Exception

litError1.Text = "Response Not Recieved"

End Try

'load Dataset

Dim ds As DataSet = New DataSet

ds.ReadXml(strData)

----------------------------------------------------------------------------
Nov 18 '05 #1
2 1594
"Martyn Fewtrell" <mf*******@networkclub.co.uk> wrote in message
news:OS**************@TK2MSFTNGP12.phx.gbl...
I am having a problem reading an Xml file and loading it into a dataset in
VB.net (ASP).

I seem to be able to load the remote file from the Url but once in memory I cant manage to load it in to a dataset.

The readXml appears to want to read a file rather than a variable and I'm
not sure how to get around this issue.

I've tried loading to a file stream and converting the strFile to an
XmlDocument but this doesn't appear to get me any further.

I known the code at the bottom doesn't work I have listed it to put over the idea of what I am trying to do.


Martyn,

The first thing you need to do is get something out of the WebResponse. If
you look at the documentation for WebResponse, you'll see that there is a
WebResponse.GetResponseStream method which returns a Stream.

Next, if you look at the documentation for DataSet.ReadXml, you'll see that
there is an overload which accepts a Stream as input. Putting this together,
you get:

'get data

Dim Url As String = "http://www.url/file.xml"
Dim Request As WebRequest
Dim Response As WebResponse
Dim strFile As String

Dim ds As DataSet = New DataSet

Try
Request = WebRequest.Create(Url)
Response = Request.GetResponse()
litError1.Text = "Response Recieved"

Dim responseStream As Stream = Response.GetResponseStream()
'load Dataset
ds.ReadXml(responseStream)
Catch ex As Exception
litError1.Text = "Response Not Recieved"
End Try

--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #2


"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
"Martyn Fewtrell" <mf*******@networkclub.co.uk> wrote in message
news:OS**************@TK2MSFTNGP12.phx.gbl...
I am having a problem reading an Xml file and loading it into a dataset in VB.net (ASP).

I seem to be able to load the remote file from the Url but once in memory
I
cant manage to load it in to a dataset.

The readXml appears to want to read a file rather than a variable and
I'm not sure how to get around this issue.

I've tried loading to a file stream and converting the strFile to an
XmlDocument but this doesn't appear to get me any further.

I known the code at the bottom doesn't work I have listed it to put over

the
idea of what I am trying to do.


Martyn,

The first thing you need to do is get something out of the WebResponse. If
you look at the documentation for WebResponse, you'll see that there is a
WebResponse.GetResponseStream method which returns a Stream.

Next, if you look at the documentation for DataSet.ReadXml, you'll see

that there is an overload which accepts a Stream as input. Putting this together, you get:

'get data

Dim Url As String = "http://www.url/file.xml"
Dim Request As WebRequest
Dim Response As WebResponse
Dim strFile As String

Dim ds As DataSet = New DataSet

Try
Request = WebRequest.Create(Url)
Response = Request.GetResponse()
litError1.Text = "Response Recieved"

Dim responseStream As Stream = Response.GetResponseStream()
'load Dataset
ds.ReadXml(responseStream)
Catch ex As Exception
litError1.Text = "Response Not Recieved"
End Try

--
John Saunders
johnwsaundersiii at hotmail

Thanks John

I shall try this this evening and see how it all fits together!

Martyn
Nov 18 '05 #3

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

Similar topics

1
by: Peter Ammon | last post by:
I would like to read from a pipe in which data may arrive slowly. From experimenting, it looks like os.read() will block until it returns the maximum amount of data you asked for, in the second...
2
by: Gunnar | last post by:
Hello, I've just written a CPP program that reads integers from a binary file, and used this code while (my_ifstram.read( (char* ) &number, sizeof(int)) { // do something with number } My...
4
by: francis70 | last post by:
Hi, I have these 2 problem? Is there a way in Oracle to read UNCOMMITED data. i.e. in Oracle the normal behaviour is that a user's updates to a table are visible to other users ONLY when the...
11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
18
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE)...
0
by: Peter | last post by:
I am having a problem reading an Excel file that is XML based. The directory I am reading contains Excel files that can be of two types. Either generic Microsoft based or XML based. I am reading...
0
by: phplasma | last post by:
Hey, I am currently attempting to implement a multi-threaded C# socket, using SSL (.pem file/certification/private key combo) server using Visual Studio C# Express. I have successfully made...
6
by: arnuld | last post by:
This works fine, I welcome any views/advices/coding-practices :) /* C++ Primer - 4/e * * Exercise 8.9 * STATEMENT: * write a program to store each line from a file into a *...
4
by: zl2k | last post by:
hi, there I have a appendable binary file of complex data structure named data.bin created by myself. It is written in the following format: number of Data, Data array Suppose I have...
1
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.