Is there an XmlWriter that writes colorful HTML output to display XML on a web page?

I have some XML that I want to display in my ASP.NET website as is (for debugging purposes) and it would be nice if it was colored. This should be easy to achieve with the right type XmlWriter

, but I don't have time to do it myself. Is there an existing (free) component that can do this?

+2


a source to share


2 answers


I would not use XmlWriter.

I would use XSLT. If the XML file should be displayed by itself, simply insert PI-stylesheet in the XML: <?xml-stylesheet type="text/xsl" href="RawXmlAsHtml.xslt"?>

. But since IE does this automatically, I assume your goal is not to render XML on your page.

Most likely, the "raw" xml should be rendered as part of another HTML page. In this case, I use a server side XSL transformation to generate HTML from XML and then insert the output into the control <asp:xml>

. Like this:

var doc= new System.Xml.XmlDocument();
doc.Load(xmlFile);
var xsl= new System.Xml.Xsl.XslTransform();
xsl.Load(Server.MapPath("RawXmlAsHtml.xslt"));
xml1.Document = doc;
xml1.Transform = xsl;

      

And the markup:

<asp:xml id="xml1" runat="server" />

      


This leaves the question of what XSLT you can use?



IE since MSXML3 has included a stylesheet for formatting raw xml. It is sometimes available via res: //msxml3.dll/defaultss.xsl. But this is not a standard XSLT stylesheet; it uses the Microsoft specific WD-xsl format. This may not be what you want.

I looked and found something that follows the XSLT standard; produced by Oleg Tkachenko and posted as part of his electronic web control . It is available under a BSD style license. (You might even need the whole exml control - I don't know what that is.)

Using this XSLT and the above code, the display looks like this:

alt text

This is not entirely ideal because this stylesheet generates a complete HTML page with tags <HTML>

, <HEAD>

etc. You really just want a snippet. But you should be able to set it up pretty easily, and anyway, it displays correctly for me, no change.


Edit : due to the mentioned problem: I changed my stylesheet to not insert tags <HTML>

and <HEAD>

. This works great.

+4


a source


This will be more of a function of your editor than of the XML file itself, so no, the XmlWriter will not.



0


a source







All Articles