XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Glenn MeadowsSubject: 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>



Unknownchart(1).xml
chart.xml

Unknownchart(1).xsl
chart.xsl

Postnext
Ivan PedruzziSubject: XmlWriter and output to a browser
Author: Ivan Pedruzzi
Date: 30 Oct 2006 11:38 PM
Glenn,

Are you sure that IIS is configured properly?

What happens if you try to reference the file directly?
http://localhost/index.svg


Ivan Pedruzzi
Stylus Studio Team

Posttop
Glenn MeadowsSubject: 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

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.