By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,133 Members | 1,092 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,133 IT Pros & Developers. It's quick & easy.

XML output in .aspx page

P: n/a
Hi

I have an .aspx web form in which I would like to output only XML, no HTML.
The datasource is a datatable that's bult on the fly based on user input
from previous .aspx page so the XML output has to be genereated in the code
behind.

I was wondering if there is an elegant way of doing this in .NET using the
..NET classes...

TIA

Steve
Nov 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
From a DataSet you can call method WriteXML.. Gives a nice XML output! Maybe
you can do that directly from a datatable as well, otherwise just add the
table to a dataset and then call that method.

/Lars Netzel

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi

I have an .aspx web form in which I would like to output only XML, no
HTML. The datasource is a datatable that's bult on the fly based on user
input from previous .aspx page so the XML output has to be genereated in
the code behind.

I was wondering if there is an elegant way of doing this in .NET using the
.NET classes...

TIA

Steve

Nov 19 '05 #2

P: n/a
Hi Lars - thx for the reply.

However, doesn't the WriteXML method write to a file? What I need to do is
make the XML what the cleint recieves when the request an .aspx page. For
example when they request http://www.mydomain.com/xml.aspx the recieve just
XML instead of <html><head></head><body>...</body></html>....

Steve

"Lars Netzel" <no****@doamin.com> wrote in message
news:Oj*************@TK2MSFTNGP11.phx.gbl...
From a DataSet you can call method WriteXML.. Gives a nice XML output!
Maybe you can do that directly from a datatable as well, otherwise just
add the table to a dataset and then call that method.

/Lars Netzel

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi

I have an .aspx web form in which I would like to output only XML, no
HTML. The datasource is a datatable that's bult on the fly based on user
input from previous .aspx page so the XML output has to be genereated in
the code behind.

I was wondering if there is an elegant way of doing this in .NET using
the .NET classes...

TIA

Steve


Nov 19 '05 #3

P: n/a
Well... don't have to write it to a file. Check out the Arguments.. there
are 8 variations.

Try a stream... that shouldn't be to hard to output as a string.

/Lars
"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Lars - thx for the reply.

However, doesn't the WriteXML method write to a file? What I need to do
is make the XML what the cleint recieves when the request an .aspx page.
For example when they request http://www.mydomain.com/xml.aspx the recieve
just XML instead of <html><head></head><body>...</body></html>....

Steve

"Lars Netzel" <no****@doamin.com> wrote in message
news:Oj*************@TK2MSFTNGP11.phx.gbl...
From a DataSet you can call method WriteXML.. Gives a nice XML output!
Maybe you can do that directly from a datatable as well, otherwise just
add the table to a dataset and then call that method.

/Lars Netzel

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi

I have an .aspx web form in which I would like to output only XML, no
HTML. The datasource is a datatable that's bult on the fly based on user
input from previous .aspx page so the XML output has to be genereated in
the code behind.

I was wondering if there is an elegant way of doing this in .NET using
the .NET classes...

TIA

Steve



Nov 19 '05 #4

P: n/a
Well you are right, Lars - & thx again for the reply

I guess the question & really have is how to get the XML INTO the .aspx page
(without the HTML) and send it back to the client. This is where I'm stuck.

I usually write for windows, but got this ASP.NET project handed to me, so I
don't really know all the tricks of making this stuff work the .aspx way...

Steve
"Lars Netzel" <no****@doamin.com> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...
Well... don't have to write it to a file. Check out the Arguments.. there
are 8 variations.

Try a stream... that shouldn't be to hard to output as a string.

/Lars
"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Lars - thx for the reply.

However, doesn't the WriteXML method write to a file? What I need to do
is make the XML what the cleint recieves when the request an .aspx page.
For example when they request http://www.mydomain.com/xml.aspx the
recieve just XML instead of
<html><head></head><body>...</body></html>....

Steve

"Lars Netzel" <no****@doamin.com> wrote in message
news:Oj*************@TK2MSFTNGP11.phx.gbl...
From a DataSet you can call method WriteXML.. Gives a nice XML output!
Maybe you can do that directly from a datatable as well, otherwise just
add the table to a dataset and then call that method.

/Lars Netzel

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi

I have an .aspx web form in which I would like to output only XML, no
HTML. The datasource is a datatable that's bult on the fly based on
user input from previous .aspx page so the XML output has to be
genereated in the code behind.

I was wondering if there is an elegant way of doing this in .NET using
the .NET classes...

TIA

Steve



Nov 19 '05 #5

P: n/a
Do you want to show the XML as XML or do you need to parse it some how?

If you only need to show it as xml, you just html-encode what you get from
the XMLWriter and put it on the page!

Unless you have the option to just redirect to the xml fil itself and the
whoel thing will just by it self..

/Lars
"Steve Peterson" <sp*******@nospam.com> skrev i meddelandet
news:u$**************@TK2MSFTNGP11.phx.gbl...
Well you are right, Lars - & thx again for the reply

I guess the question & really have is how to get the XML INTO the .aspx
page (without the HTML) and send it back to the client. This is where I'm
stuck.

I usually write for windows, but got this ASP.NET project handed to me, so
I don't really know all the tricks of making this stuff work the .aspx
way...

Steve
"Lars Netzel" <no****@doamin.com> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...
Well... don't have to write it to a file. Check out the Arguments..
there are 8 variations.

Try a stream... that shouldn't be to hard to output as a string.

/Lars
"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Lars - thx for the reply.

However, doesn't the WriteXML method write to a file? What I need to do
is make the XML what the cleint recieves when the request an .aspx page.
For example when they request http://www.mydomain.com/xml.aspx the
recieve just XML instead of
<html><head></head><body>...</body></html>....

Steve

"Lars Netzel" <no****@doamin.com> wrote in message
news:Oj*************@TK2MSFTNGP11.phx.gbl...
From a DataSet you can call method WriteXML.. Gives a nice XML output!
Maybe you can do that directly from a datatable as well, otherwise just
add the table to a dataset and then call that method.

/Lars Netzel

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> Hi
>
> I have an .aspx web form in which I would like to output only XML, no
> HTML. The datasource is a datatable that's bult on the fly based on
> user input from previous .aspx page so the XML output has to be
> genereated in the code behind.
>
> I was wondering if there is an elegant way of doing this in .NET using
> the .NET classes...
>
> TIA
>
> Steve
>



Nov 19 '05 #6

P: n/a
Thx for your reply again, Lars

No - I don't want to html-encode it. I just want the page to contain XML
instead of HTML. Il looked at the XML writer & yes - that's what I need.
But, how to I get it into the page? Is there some control I can bind it to
or anything like that?

Steve

"Lars Netzel" <tr*****@apa.se> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Do you want to show the XML as XML or do you need to parse it some how?

If you only need to show it as xml, you just html-encode what you get from
the XMLWriter and put it on the page!

Unless you have the option to just redirect to the xml fil itself and the
whoel thing will just by it self..

/Lars
"Steve Peterson" <sp*******@nospam.com> skrev i meddelandet
news:u$**************@TK2MSFTNGP11.phx.gbl...
Well you are right, Lars - & thx again for the reply

I guess the question & really have is how to get the XML INTO the .aspx
page (without the HTML) and send it back to the client. This is where I'm
stuck.

I usually write for windows, but got this ASP.NET project handed to me,
so I don't really know all the tricks of making this stuff work the .aspx
way...

Steve
"Lars Netzel" <no****@doamin.com> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...
Well... don't have to write it to a file. Check out the Arguments..
there are 8 variations.

Try a stream... that shouldn't be to hard to output as a string.

/Lars
"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi Lars - thx for the reply.

However, doesn't the WriteXML method write to a file? What I need to
do is make the XML what the cleint recieves when the request an .aspx
page. For example when they request http://www.mydomain.com/xml.aspx
the recieve just XML instead of
<html><head></head><body>...</body></html>....

Steve

"Lars Netzel" <no****@doamin.com> wrote in message
news:Oj*************@TK2MSFTNGP11.phx.gbl...
> From a DataSet you can call method WriteXML.. Gives a nice XML output!
> Maybe you can do that directly from a datatable as well, otherwise
> just add the table to a dataset and then call that method.
>
> /Lars Netzel
>
> "Steve Peterson" <sp*******@nospam.com> wrote in message
> news:%2****************@TK2MSFTNGP10.phx.gbl...
>> Hi
>>
>> I have an .aspx web form in which I would like to output only XML, no
>> HTML. The datasource is a datatable that's bult on the fly based on
>> user input from previous .aspx page so the XML output has to be
>> genereated in the code behind.
>>
>> I was wondering if there is an elegant way of doing this in .NET
>> using the .NET classes...
>>
>> TIA
>>
>> Steve
>>
>
>



Nov 19 '05 #7

P: n/a
Hello Steve,

How about:

private void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";

DataSet myDataSet = SomeMethodToGetADataSet();
myDataSet.WriteXml(Response.OutputStream);

Response.Flush();
Response.End();
}

--
Matt Berther
http://www.mattberther.com
Thx for your reply again, Lars

No - I don't want to html-encode it. I just want the page to contain
XML instead of HTML. Il looked at the XML writer & yes - that's what I
need. But, how to I get it into the page? Is there some control I can
bind it to or anything like that?

Steve

"Lars Netzel" <tr*****@apa.se> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Do you want to show the XML as XML or do you need to parse it some
how?

If you only need to show it as xml, you just html-encode what you get
from the XMLWriter and put it on the page!

Unless you have the option to just redirect to the xml fil itself and
the whoel thing will just by it self..

/Lars

"Steve Peterson" <sp*******@nospam.com> skrev i meddelandet
news:u$**************@TK2MSFTNGP11.phx.gbl...
Well you are right, Lars - & thx again for the reply

I guess the question & really have is how to get the XML INTO the
.aspx page (without the HTML) and send it back to the client. This
is where I'm stuck.

I usually write for windows, but got this ASP.NET project handed to
me, so I don't really know all the tricks of making this stuff work
the .aspx way...

Steve

"Lars Netzel" <no****@doamin.com> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...

Well... don't have to write it to a file. Check out the
Arguments.. there are 8 variations.

Try a stream... that shouldn't be to hard to output as a string.

/Lars

"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...

> Hi Lars - thx for the reply.
>
> However, doesn't the WriteXML method write to a file? What I need
> to do is make the XML what the cleint recieves when the request an
> .aspx page. For example when they request
> http://www.mydomain.com/xml.aspx the recieve just XML instead of
> <html><head></head><body>...</body></html>....
>
> Steve
>
> "Lars Netzel" <no****@doamin.com> wrote in message
> news:Oj*************@TK2MSFTNGP11.phx.gbl...
>
>> From a DataSet you can call method WriteXML.. Gives a nice XML
>> output! Maybe you can do that directly from a datatable as well,
>> otherwise just add the table to a dataset and then call that
>> method.
>>
>> /Lars Netzel
>>
>> "Steve Peterson" <sp*******@nospam.com> wrote in message
>> news:%2****************@TK2MSFTNGP10.phx.gbl...
>>
>>> Hi
>>>
>>> I have an .aspx web form in which I would like to output only
>>> XML, no HTML. The datasource is a datatable that's bult on the
>>> fly based on user input from previous .aspx page so the XML
>>> output has to be genereated in the code behind.
>>>
>>> I was wondering if there is an elegant way of doing this in .NET
>>> using the .NET classes...
>>>
>>> TIA
>>>
>>> Steve
>>>

Nov 19 '05 #8

P: n/a
Response.Clear(); // remove any html in the buffer (or aspx page)
XmlTextWriter xml = new XmlTextWriter(Response.OutputStream,null);

// now use xmlwriter to output xml
-- bruce (sqlwork.com)
"Steve Peterson" <sp*******@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
| Hi
|
| I have an .aspx web form in which I would like to output only XML, no
HTML.
| The datasource is a datatable that's bult on the fly based on user input
| from previous .aspx page so the XML output has to be genereated in the
code
| behind.
|
| I was wondering if there is an elegant way of doing this in .NET using the
| .NET classes...
|
| TIA
|
| Steve
|
|
Nov 19 '05 #9

P: n/a
thx matt for your reply!

I dound another solution (I can't believe I missed it before) is simply
'mydataset.GetXML'. I put one literal control in the page (I set the
ContentType="text/xml" attribute in the @Page directive & whacked all the
autogenerated HTML), then in code behind its:

...(code to get data set)
mylitcontrol.text = mydataset.GetXML

Viola!

Steve


"Matt Berther" <mb******@hotmail.com> wrote in message
news:73***********************@news.microsoft.com. ..
Hello Steve,

How about:

private void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "text/xml";

DataSet myDataSet = SomeMethodToGetADataSet();
myDataSet.WriteXml(Response.OutputStream);

Response.Flush();
Response.End();
}

--
Matt Berther
http://www.mattberther.com
Thx for your reply again, Lars

No - I don't want to html-encode it. I just want the page to contain
XML instead of HTML. Il looked at the XML writer & yes - that's what I
need. But, how to I get it into the page? Is there some control I can
bind it to or anything like that?

Steve

"Lars Netzel" <tr*****@apa.se> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Do you want to show the XML as XML or do you need to parse it some
how?

If you only need to show it as xml, you just html-encode what you get
from the XMLWriter and put it on the page!

Unless you have the option to just redirect to the xml fil itself and
the whoel thing will just by it self..

/Lars

"Steve Peterson" <sp*******@nospam.com> skrev i meddelandet
news:u$**************@TK2MSFTNGP11.phx.gbl...

Well you are right, Lars - & thx again for the reply

I guess the question & really have is how to get the XML INTO the
.aspx page (without the HTML) and send it back to the client. This
is where I'm stuck.

I usually write for windows, but got this ASP.NET project handed to
me, so I don't really know all the tricks of making this stuff work
the .aspx way...

Steve

"Lars Netzel" <no****@doamin.com> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...

> Well... don't have to write it to a file. Check out the
> Arguments.. there are 8 variations.
>
> Try a stream... that shouldn't be to hard to output as a string.
>
> /Lars
>
> "Steve Peterson" <sp*******@nospam.com> wrote in message
> news:%2****************@tk2msftngp13.phx.gbl...
>
>> Hi Lars - thx for the reply.
>>
>> However, doesn't the WriteXML method write to a file? What I need
>> to do is make the XML what the cleint recieves when the request an
>> .aspx page. For example when they request
>> http://www.mydomain.com/xml.aspx the recieve just XML instead of
>> <html><head></head><body>...</body></html>....
>>
>> Steve
>>
>> "Lars Netzel" <no****@doamin.com> wrote in message
>> news:Oj*************@TK2MSFTNGP11.phx.gbl...
>>
>>> From a DataSet you can call method WriteXML.. Gives a nice XML
>>> output! Maybe you can do that directly from a datatable as well,
>>> otherwise just add the table to a dataset and then call that
>>> method.
>>>
>>> /Lars Netzel
>>>
>>> "Steve Peterson" <sp*******@nospam.com> wrote in message
>>> news:%2****************@TK2MSFTNGP10.phx.gbl...
>>>
>>>> Hi
>>>>
>>>> I have an .aspx web form in which I would like to output only
>>>> XML, no HTML. The datasource is a datatable that's bult on the
>>>> fly based on user input from previous .aspx page so the XML
>>>> output has to be genereated in the code behind.
>>>>
>>>> I was wondering if there is an elegant way of doing this in .NET
>>>> using the .NET classes...
>>>>
>>>> TIA
>>>>
>>>> Steve
>>>>


Nov 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.