Retrieve an XML stream from my business class

G

Grant Merwitz

I am trying to write an XML file from my database.

Currently, i have this code on an ASPX page, but have also built a business
layer that manages all the DataRetrieval and is reference in my main ASP.NET
project.
I would like to retrieve either a stream/XmlTextWriter from the Business
layer, that i can just retrieve and write from the front end,

Whats the best method to do this?


Any advice would be greatly appreciated

Currenlty, i am writing the code directly on the page as follows:
(obviously bogus data here, as i'm just getting it to work before i use real
data - also, this is in a control, hence Page.Response)

Page.Response.Clear();

Page.Response.ContentType = "text/xml";

XmlTextWriter xr = new XmlTextWriter(Page.Response.OutputStream,
System.Text.Encoding.UTF8);

//Write opening elements

xr.WriteStartDocument();

xr.WriteStartElement("rss");

xr.WriteAttributeString("version","2.0");

xr.WriteStartElement("channel");

xr.WriteElementString("title", "Workshare Corporate Blog");

xr.WriteElementString("link", "http://www.workshare.com/company/blog");

xr.WriteElementString("description", "Latest news from Workshare.COM");

xr.WriteElementString("copyright", "(c) Workshare.com");

xr.WriteElementString("ttl","5");

//Write the articles

xr.WriteStartElement("item");

xr.WriteElementString("title","title1");

xr.WriteElementString("description","this is title 1");

xr.WriteElementString("link","http://www.workshare.com");

xr.WriteElementString("pubDate", DateTime.Now.ToString());

xr.WriteEndElement();

xr.WriteStartElement("item");

xr.WriteElementString("title","title2");

xr.WriteElementString("description","this is title 2");

xr.WriteElementString("link","http://www.workshare.com");

xr.WriteElementString("pubDate", DateTime.Now.ToString());

xr.WriteEndElement();

//Close the opening elements

xr.WriteEndElement();

xr.WriteEndElement();

xr.WriteEndDocument();

xr.Flush();

xr.Close();

Page.Response.End();
 
G

Grant Merwitz

Got it, just posting up so no one has to worry


I chagned my method to be a return type of String

Them wrote the XmlTextReader directly to a memorystream,
Then using the StreamReader, wrote the to a string.

I'm happy now :)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top