I have a web application that creates XML feeds on the fly, depending on criteria passed in via the query string.
It is a very simple application: it reads the query string variables, and uses them to format data (cached data from the database) into the appropriate XML format.
The returned XML file is about 25MB... there is a lot of data.
I am using an XmlTextWriter to build the XML, and then returning that to the requestor as an "application/octet-stream" - an attachment they can download.
Question is: Building the XML seems to use 100% of the CPU and is causing problems with my other applications.
Does anyone have experience with building such large XML files? Any tips on making the process less CPU intensive?
Code sample is:
map.WriteRaw("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
map.WriteStartElement("rss");
map.WriteAttributeString("version", "2.0");
map.WriteAttributeString("xmlns:g", "http://base.google.com/ns/1.0");
map.WriteStartElement("channel");
map.WriteElementString("link", "http://www.mywebsite.com...");
ProductCollection items = Product.GetCachedSiteProducts();
foreach (Product p in items)
{
map.WriteStartElement("item");
........
map.WriteElementString("description", p.Description);
map.WriteElementString("g:id", p.SiteSku);
map.WriteElementString("g:condition", "new");
map.WriteElementString("g:price", p.Price.ToString() + " USD");
...............
map.WriteEndElement(); //item
}
}
map.WriteEndElement();//channel
map.WriteEndElement();//rss
Response.Write(sw.ToString());
UPDATE: I am answering my own question.. thanks to those who asked me to post more code, this was an easy one when I looked more carefully.
Code was using "Response.write(map.ToString())" to output the xml. Wow, that's inefficient. Will update the code. Thanks all!