|
next
|
 Subject: XmlWriter and output to a browser Author: Glenn Meadows Date: 30 Oct 2006 01:37 PM
|
Hi folks,
I have ASP.NET code which correctly writes results to a file. If I change the code in an attempt to display the data to a browser, I see only a blank screen.
You only need to comment and uncomment one of the lines at the bottom of the file where an XmlWriter object is instantiated.
I am working with an SVG file (Scalable Vector Graphics (a W3C standard) - much like XML) which renders a graphical image to a browser.
In order to run the code you will need first to create a directory on your c drive named WebSite. When using the ASP.NET code to write a file, the code writes the file svgOutput.svg to your local C:\WebSite directory. Open this file in your IE browser and you will see a barchart.
Again, if I attempt to view the barchart in the browser and not write the file to disk, I see only a blank screen.
I am transforming the chart.xsl and chart.xml files found in the SS examples in the SVG directory. The output is an SVG file using ASP.NET 2.0. The XSL and XML files are attached or you can see them in your SS examples\svg directory.
/////////// ASP.NET file ////////////////////
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
Response.AddHeader("Content-Type", "image/svg+xml");
string xmlPath = Request.PhysicalApplicationPath + @"chart.xml";
string xslPath = Request.PhysicalApplicationPath + @"chart.xsl";
XmlReader rdr = null;
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XslCompiledTransform transform = new XslCompiledTransform();
//Load the XML into the XslCompiledTransform object
transform.Load(xslPath);
XPathDocument xpathDoc = new XPathDocument(xmlPath);
rdr = XmlReader.Create(xslPath, settings);
XmlWriter wrtr = XmlWriter.Create ("c:\\website\\svgOutput.svg");
//XmlWriter wrtr = XmlWriter.Create(Response.OutputStream);
transform.Transform(xpathDoc, null, wrtr);
}
</script>
chart(1).xml chart.xml
chart(1).xsl chart.xsl
|
top
|
 Subject: XmlWriter and output to a browser Author: Glenn Meadows Date: 31 Oct 2006 07:34 AM
|
Hi Ivan,
I have fixed this problem and I would like to submit the ASP.NET code to the SS team and all SS users.
To view the SVG using chart.xml and chart.xsl with ASP.NET use the following code. I am running IE 6, ASP.NET 2.0 and Windows XP SP2.
In order for this code to work, you must append to your aspx file in your URL with a ?dummy=.svg For example,
http://domain name/filename.aspx?dummy=.svg
You need to do this because IIS and/or IE does not recognize the mime type for the SVG file. Here's the code...
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<script runat="server">
void Page_Load(object sender, System.EventArgs e)
{
Response.AddHeader("Content-Type", "image/svg+xml");
string xmlPath = Request.PhysicalApplicationPath + @"chart.xml";
string xslPath = Request.PhysicalApplicationPath + @"chart.xsl";
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreWhitespace = true;
settings.IgnoreComments = true;
XslCompiledTransform transform = new XslCompiledTransform();
//Load the XML into the XslCompiledTransform object
transform.Load(xslPath);
XPathDocument xpathDoc = new XPathDocument(xmlPath);
XmlReader rdr = XmlReader.Create(xslPath, settings);
XmlWriter wrtr = XmlWriter.Create(Response.OutputStream);
transform.Transform(xpathDoc, null, wrtr);
}
</script>
Enjoy,
-Glenn
|
|
|