Displaying XML (raw) from an ASP.NET Document

J

Jesse Liberty

Hi. [if this is a repost, forgive me, but I didn't see the original posted]

I'd like to create an xml document on the fly and then display it in an
asp.net page. I can use an iframe and point to a URL (which displays
perfectly), but I'd not like to save the xml to a file (it will be built as
I go along).

I can use the <asp:xml> control, but I don't want to have to write the XSLT,
I love the one I get for free within IFrame.

Any suggestions?

Thanks.
 
J

Jesse Liberty

Figured out the answer to my own question. I thought I'd post it in case
anyone is interested...

1) Create a page with an IFrame on it. Set the src to a second page
2) On the second aspx page, remove all the html except the Page directive
(do remove the !doctype etc.)
3) In thepage load of the second page create a memory stream and an
XMLSerializer
4. Serialize your object to the memory stream. Then use ToArray() on the
memory stream to write the
serialized document to a byte array. Then use Encoding.ASCII.GetString to
write the byte array to a string, finally, use Response.Write to write the
string. This will be displayed in the IFrame on the first page.

Works great.
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top