HI All, I have an XML output coming back from a ssh connection and want to display the results cleanly on a webpage. What control is best suited for passing an XML string? Do any of them give expand/collapse functionality as with IE? Thanks and Regards, Al
Use <pre>
tags to wrap the contents, and then replace all the Xml file's "<" brackets with "<
" and the ">" ones with ">
". E.g.
<pre>
<?xml version="1.0" encoding="utf-8"?>
<rootNode>
<subnode>Subnode</subnode>
</rootNode>
</pre>
which displays as
<?xml version="1.0" encoding="utf-8"?>
<rootNode>
<subnode>Subnode</subnode>
</rootNode>
in a web page.
If you want the colorization/expand/collapse functionality found in IE, the best way is probably to use something like the XSLT transform that IE uses. Here is a post from xsl-list that contains a usable version of the transform. (I believe that the actual transform IE uses is, even now, XSL-WD, not XSLT; but the version I linked to is reworked to use XSLT.)
This transform generates an entire web page. If you want to make use it from inside a web page (especially if you want to display multiple XML documents on the same page), you're going to have to tweak it some, e.g. extract the stylesheet and script into separate files that your page references instead of having the transform emit them, so you don't end up with eight copies of them in your page.
I've used this transform (plus a WebBrowser
control) to build a little XML visualizer class that I use in my desktop apps, and it works like a charm.