dataset as xml to client

J

John Boers

I have an aspx page that reads info from a database and puts in in a
dataset. Then an XML-file is created by a myDataset.WriteXml("myInfo.xml")
statement.

After that the XML-file must be read by an aspx-page that resides on
anaother server. I do that as follows
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/myInfo.xml").

Then I put the info in a dataset:
Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)

And then the processing continues on my local webserver.

I would like to make a page that don't writes the xml to a file but that
sends it directly to the calling client. I fact I want to call an
aspx-pages that creates the xml and sends it direct to the calling page,
like
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/GiveMeMyInfo.aspx")

The trick is i call an aspx-page but want xml back, can anybody tell me how
to do that?

John
 
K

Ken Cox [Microsoft MVP]

Hi John,

Here's some code that should point the way. Just put this in an .aspx page
with no other content (no HTML at all) and execute it.

<%@ Page Language="vb" AutoEventWireup="true"%>
<script language=vb runat=server>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' By Ken Cox for John Boers
' July 18/2004
Dim myDataSet As New system.data.DataSet
myDataSet.Tables.Add(CreateDataSource())
Dim xmlDoc As System.Xml.XmlDataDocument = _
New System.Xml.XmlDataDocument(myDataSet)
Response.Clear()
Response.ClearHeaders()
Response.ContentType = "text/xml"
Response.Write(xmlDoc.InnerXml)
End Sub
Function CreateDataSource() As _
system.data.DataTable
Dim dt As New system.data.DataTable
Dim dr As system.data.DataRow
dt.Columns.Add(New system.data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New system.data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New system.data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New system.data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>


Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto
 
J

John Boers

Hi John,

Here's some code that should point the way. Just put this in an .aspx page
with no other content (no HTML at all) and execute it.

<%@ Page Language="vb" AutoEventWireup="true"%>
<script language=vb runat=server>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' By Ken Cox for John Boers
' July 18/2004
Dim myDataSet As New system.data.DataSet
myDataSet.Tables.Add(CreateDataSource())
Dim xmlDoc As System.Xml.XmlDataDocument = _
New System.Xml.XmlDataDocument(myDataSet)
Response.Clear()
Response.ClearHeaders()
Response.ContentType = "text/xml"
Response.Write(xmlDoc.InnerXml)
End Sub
Function CreateDataSource() As _
system.data.DataTable
Dim dt As New system.data.DataTable
Dim dr As system.data.DataRow
dt.Columns.Add(New system.data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New system.data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New system.data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New system.data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>


Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto


John Boers said:
I have an aspx page that reads info from a database and puts in in a
dataset. Then an XML-file is created by a myDataset.WriteXml("myInfo.xml")
statement.

After that the XML-file must be read by an aspx-page that resides on
anaother server. I do that as follows
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/myInfo.xml").

Then I put the info in a dataset:
Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)

And then the processing continues on my local webserver.

I would like to make a page that don't writes the xml to a file but that
sends it directly to the calling client. I fact I want to call an
aspx-pages that creates the xml and sends it direct to the calling page,
like
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/GiveMeMyInfo.aspx")

The trick is i call an aspx-page but want xml back, can anybody tell me
how
to do that?

John

Hello Ken,

I just tested your example, it works great. I never thought about the
content-type option.

Thanks,

John
 
J

John Boers

Hello Ken,

I implemented your solution in my application and it is workin great.

I am now really sharing information between a global and a local server.
The combination of ASP.NET and XML proves to be very powerfull.

Thanks again,

John


Hi John,

Here's some code that should point the way. Just put this in an .aspx page
with no other content (no HTML at all) and execute it.

<%@ Page Language="vb" AutoEventWireup="true"%>
<script language=vb runat=server>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' By Ken Cox for John Boers
' July 18/2004
Dim myDataSet As New system.data.DataSet
myDataSet.Tables.Add(CreateDataSource())
Dim xmlDoc As System.Xml.XmlDataDocument = _
New System.Xml.XmlDataDocument(myDataSet)
Response.Clear()
Response.ClearHeaders()
Response.ContentType = "text/xml"
Response.Write(xmlDoc.InnerXml)
End Sub
Function CreateDataSource() As _
system.data.DataTable
Dim dt As New system.data.DataTable
Dim dr As system.data.DataRow
dt.Columns.Add(New system.data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New system.data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New system.data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New system.data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>


Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto


John Boers said:
I have an aspx page that reads info from a database and puts in in a
dataset. Then an XML-file is created by a myDataset.WriteXml("myInfo.xml")
statement.

After that the XML-file must be read by an aspx-page that resides on
anaother server. I do that as follows
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/myInfo.xml").

Then I put the info in a dataset:
Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)

And then the processing continues on my local webserver.

I would like to make a page that don't writes the xml to a file but that
sends it directly to the calling client. I fact I want to call an
aspx-pages that creates the xml and sends it direct to the calling page,
like
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/GiveMeMyInfo.aspx")

The trick is i call an aspx-page but want xml back, can anybody tell me
how
to do that?

John
 
K

Ken Cox [Microsoft MVP]

Hi John,

Thanks for reporting back!

It is nice to know when something solves a problem - and I'm sure future
Googlers will appreciate knowing too!

Ken



John Boers said:
Hello Ken,

I implemented your solution in my application and it is workin great.

I am now really sharing information between a global and a local server.
The combination of ASP.NET and XML proves to be very powerfull.

Thanks again,

John


Hi John,

Here's some code that should point the way. Just put this in an .aspx
page
with no other content (no HTML at all) and execute it.

<%@ Page Language="vb" AutoEventWireup="true"%>
<script language=vb runat=server>
Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
' By Ken Cox for John Boers
' July 18/2004
Dim myDataSet As New system.data.DataSet
myDataSet.Tables.Add(CreateDataSource())
Dim xmlDoc As System.Xml.XmlDataDocument = _
New System.Xml.XmlDataDocument(myDataSet)
Response.Clear()
Response.ClearHeaders()
Response.ContentType = "text/xml"
Response.Write(xmlDoc.InnerXml)
End Sub
Function CreateDataSource() As _
system.data.DataTable
Dim dt As New system.data.DataTable
Dim dr As system.data.DataRow
dt.Columns.Add(New system.data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New system.data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New system.data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New system.data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 8
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>


Does this help?

Ken
Microsoft MVP [ASP.NET]
Toronto


John Boers said:
I have an aspx page that reads info from a database and puts in in a
dataset. Then an XML-file is created by a
myDataset.WriteXml("myInfo.xml")
statement.

After that the XML-file must be read by an aspx-page that resides on
anaother server. I do that as follows
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/myInfo.xml").

Then I put the info in a dataset:
Dim ds as DataSet = New DataSet()
ds.ReadXml(reader)

And then the processing continues on my local webserver.

I would like to make a page that don't writes the xml to a file but that
sends it directly to the calling client. I fact I want to call an
aspx-pages that creates the xml and sends it direct to the calling page,
like
Dim reader as XmlTextReader = New
XmlTextReader("http://companywebsite.nl/GiveMeMyInfo.aspx")

The trick is i call an aspx-page but want xml back, can anybody tell me
how
to do that?

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top