473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

XML, XSL and ASP.NET

Hi folks,

My problem is this...

I am having an issue with whitespace between XML tags that occurs when I
transform the XSL output to the browser via ASP.NET leaving me with
unexpected results.

Read on if you dare.

I have a XML file (datum.xml) that contains numeric values as shown here

<datums>
<datum>18</datum>
<datum>35</datum>
<datum87</datum>
</datum>

I have a XSL file that extracts the data from the XML and generates SVG
(Scalable Vector Graphics). SVG is a W3C standard, much like XML, used to
describe graphic images.

The transformation occurs in my ASP.NET file as shown here...

<%@ 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 + @"datum.xml";
string xslPath = Request.PhysicalApplicationPath + @"datum.xsl";

XmlReader rdr = XmlReader.Create(xmlPath);
XslCompiledTransform transform = new XslCompiledTransform ();

//Load the XSL stylsheet into the XslCompiledTransform object
transform.Load(xslPath);

transform.Transform(rdr, null, Response.Output);
}
</script>

If the first line in my Page_Load function is commented out, the SVG is
displayed as text in the browser. If I uncomment the same line, I tell the
browser I am outputting SVG and I "expect" this to occur. It does not occur.

So I do a few tests. First I run the web app to view the SVG text displayed
in the browser that is shown here.

<?xml version="1.0" encoding="utf-8" ?>
- <svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">
<rect x="10" y="77" width="10" height="23" fill="red" stroke="black" />
<rect x="20" y="6" width="10" height="94" fill="red" stroke="black" />
<rect x="30" y="45" width="10" height="55" fill="red" stroke="black" />
</svg>

Next I copy the text as is and paste it into NotePad and then I save the
file as test1.svg. I then open my IE browser and select File->Open. I click
browse and select test1.svg. I click Ok and see a blank screen.

Finally I copy the same text in NotePad but this time I remove every space
and
CRLF between the tags. I save this file as test2.svg. I open my IE browser
and click File->Open to open test2.svg and I see a barchart which is my
expected result.

What I need to do is find a way to remove the whitespace and CRLF between
the tags in my ASP.NET code.

Any thoughts, ideas are welcome.
- Glenn


Oct 28 '06 #1
4 2127
Glenn wrote:
- <svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">
You need
<svg xmlns="http://www.w3.org/2000/svg"
to make sure the svg element and its descendants are in the SVG namespace.
Or, if you really want to use xmlns:svg="http://www.w3.org/2000/svg"
then you need to mark up your element as e.g.
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" ...>
<svg:rect .../>
</svg:svg>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 28 '06 #2
Martin,

Yes, I understand I need the xmlns:svg.

My issue involves how the SVG output is passed to the browser. If I take
the text that is displayed to the browser and remove all whitespace and CRLF
then the SVG
would look like this. You can copy and paste this into NotePad, save the
file and then open the file in IE where you will see the graphic image of the
barchart. Here's the SVG ...

<?xml version="1.0" encoding="utf-8" ?><svg height="100" width="100"
viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg"><rect x="10" y="77" width="10"
height="23" fill="red" stroke="black" /><rect x="20" y="6" width="10"
height="94" fill="red" stroke="black" /><rect x="30" y="45" width="10"
height="55" fill="red" stroke="black" /></svg>

"Martin Honnen" wrote:
Glenn wrote:
- <svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">

You need
<svg xmlns="http://www.w3.org/2000/svg"
to make sure the svg element and its descendants are in the SVG namespace.
Or, if you really want to use xmlns:svg="http://www.w3.org/2000/svg"
then you need to mark up your element as e.g.
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" ...>
<svg:rect .../>
</svg:svg>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Oct 28 '06 #3
Try this way, with svg as defaultnamespace
<?xml version="1.0" encoding="utf-8" ?><svg height="100" width="100"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"><rect x="10" y="77" width="10"
height="23" fill="red" stroke="black" /><rect x="20" y="6" width="10"
height="94" fill="red" stroke="black" /><rect x="30" y="45" width="10"
height="55" fill="red" stroke="black" /></svg>

or that way
<?xml version="1.0" encoding="utf-8" ?>
<svg:svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">
<svg:rect x="10" y="77" width="10" height="23" fill="red" stroke="black" />
<svg:rect x="20" y="6" width="10" height="94" fill="red" stroke="black" />
<svg:rect x="30" y="45" width="10" height="55" fill="red" stroke="black" />
</svg:svg>
hth
WilliB
"Glenn" <Gl***@discussions.microsoft.comwrote in message
news:45**********************************@microsof t.com...
Martin,

Yes, I understand I need the xmlns:svg.

My issue involves how the SVG output is passed to the browser. If I take
the text that is displayed to the browser and remove all whitespace and
CRLF
then the SVG
would look like this. You can copy and paste this into NotePad, save the
file and then open the file in IE where you will see the graphic image of
the
barchart. Here's the SVG ...

<?xml version="1.0" encoding="utf-8" ?><svg height="100" width="100"
viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg"><rect x="10" y="77" width="10"
height="23" fill="red" stroke="black" /><rect x="20" y="6" width="10"
height="94" fill="red" stroke="black" /><rect x="30" y="45" width="10"
height="55" fill="red" stroke="black" /></svg>

"Martin Honnen" wrote:
Glenn wrote:
- <svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">
You need
<svg xmlns="http://www.w3.org/2000/svg"
to make sure the svg element and its descendants are in the SVG
namespace.
Or, if you really want to use xmlns:svg="http://www.w3.org/2000/svg"
then you need to mark up your element as e.g.
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" ...>
<svg:rect .../>
</svg:svg>

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

Oct 29 '06 #4
willib,

Thanks for your help. I have made new ground and have successfully been
able to have my transform method write a SVG file out. This time I am using
different XML and XSL files for no real reason really so don't let this be of
concern as they do work together since the newly created SVG file when opened
in the browser displays the correct results.

I am now trying to get the file to automatically open by calling
Response.Output as shown in my code below...

<%@ 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.Output);

transform.Transform(xpathDoc, null, wrtr);
}
</script>

The line that instantiates the wrtr object works if you write to the
svgOutput.svg file
but if you comment the first line and uncomment the second line and pass
Response.Output, the screen is blank.

Any thoughts are appreciated.
-Glenn
"willib" wrote:
Try this way, with svg as defaultnamespace
<?xml version="1.0" encoding="utf-8" ?><svg height="100" width="100"
viewBox="0 0 100 100"
xmlns="http://www.w3.org/2000/svg"><rect x="10" y="77" width="10"
height="23" fill="red" stroke="black" /><rect x="20" y="6" width="10"
height="94" fill="red" stroke="black" /><rect x="30" y="45" width="10"
height="55" fill="red" stroke="black" /></svg>

or that way
<?xml version="1.0" encoding="utf-8" ?>
<svg:svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">
<svg:rect x="10" y="77" width="10" height="23" fill="red" stroke="black" />
<svg:rect x="20" y="6" width="10" height="94" fill="red" stroke="black" />
<svg:rect x="30" y="45" width="10" height="55" fill="red" stroke="black" />
</svg:svg>
hth
WilliB
"Glenn" <Gl***@discussions.microsoft.comwrote in message
news:45**********************************@microsof t.com...
Martin,

Yes, I understand I need the xmlns:svg.

My issue involves how the SVG output is passed to the browser. If I take
the text that is displayed to the browser and remove all whitespace and
CRLF
then the SVG
would look like this. You can copy and paste this into NotePad, save the
file and then open the file in IE where you will see the graphic image of
the
barchart. Here's the SVG ...

<?xml version="1.0" encoding="utf-8" ?><svg height="100" width="100"
viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg"><rect x="10" y="77" width="10"
height="23" fill="red" stroke="black" /><rect x="20" y="6" width="10"
height="94" fill="red" stroke="black" /><rect x="30" y="45" width="10"
height="55" fill="red" stroke="black" /></svg>

"Martin Honnen" wrote:
Glenn wrote:
>
- <svg height="100" width="100" viewBox="0 0 100 100"
xmlns:svg="http://www.w3.org/2000/svg">
>
You need
<svg xmlns="http://www.w3.org/2000/svg"
to make sure the svg element and its descendants are in the SVG
namespace.
Or, if you really want to use xmlns:svg="http://www.w3.org/2000/svg"
then you need to mark up your element as e.g.
<svg:svg xmlns:svg="http://www.w3.org/2000/svg" ...>
<svg:rect .../>
</svg:svg>
>
>
>
>
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
>


Oct 30 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.