all groups > dotnet xml > september 2006 >
You're in the

dotnet xml

group:

Display XML in WebBrowser Control


Display XML in WebBrowser Control Webbert
9/27/2006 4:23:02 AM
dotnet xml:
I am trying to display XML in a WebBrowser Control. I receive a data feed of
XML and am trying to inject it into the control. I have not been successful
in doing so.

The only solution I have found is to write it to a temp file and then use
the Navigate method to load it. As the control is capable of loading it from
disk, I would like to find a way to skip the save/load and just inject.

Thanks,
Re: Display XML in WebBrowser Control Webbert
9/27/2006 10:01:03 AM
The collapsable is nice but not required.

You said..."run the XSLT transformation with .NET to transform the XML to
HTML".
What would I used to do the transformation? Does a generic XSL exist? As
the data I am working on is not known, I can't very well create a specific
XSL.

Thanks,
Dave


[quoted text, click to view]
Re: Display XML in WebBrowser Control Martin Honnen
9/27/2006 6:35:52 PM


[quoted text, click to view]

What kind of "XML display" are you looking for? That collapsible pretty
print of the XML source tree that you get when you load an XML document
in an IE browser window? That is done with an XSL stylesheet that IE
applies using MSXML. Unfortunately I don't think it is possible to get
IE or the WebBrowser control to do that if you have a string with
markup. What you could do in a .NET 2.0 application however is to run
the XSLT transformation with .NET to transform the XML to HTML and then
set the DocumentText property of the control.

--

Martin Honnen --- MVP XML
Re: Display XML in WebBrowser Control Dimitre Novatchev
9/27/2006 7:25:12 PM
[quoted text, click to view]

Proven possible -- see the code of the XPath Visualizer for details.

Another remark: defaultss.xsl is not written in XSLT, as we well know.

Cheers,
Dimitre Novatchev


[quoted text, click to view]

Re: Display XML in WebBrowser Control Webbert
9/28/2006 1:14:02 PM
Dimitre,

I pulled down the Visualizer and experienced some problems. As a note to the
Readme, you might want to include that if you are experiencing issues with
XML files other than the ones that you provide, that they should check the
property of your files. If any of the files say "unblock" then they should.
This will fix the problem. Took me a while to figure this out.

On to the question...
If I load your Authors.xml and myDefaultss80.xml file into XML Spy and try
to transform, I get an error on
Line 323: <xsl:template match="@*|@xmlns:*|@xmlns|@xml:*|@dt:*|@d2:*">
Invalid prefixError in XPath expression, Invalid prefix

If I try to transform using .NET and the following code

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load( @"..\..\myDefaultss80.xsl" );
xslt.Transform( @"..\..\input.xml", @"..\..\authors.xml" );

an Exception is thrown, "Prefix 'xmlns' is not defined."

Any thoughts are appreciated.

Thanks,
Dave


[quoted text, click to view]
Re: Display XML in WebBrowser Control Martin Honnen
9/28/2006 2:00:52 PM


[quoted text, click to view]

Well if you use a stylesheet to transform the XML markup to HTML and
then have IE render that HTML (e.g. by document.writing it with script)
then it is possible. That is why I told the original poster that he can
of course get the display he wants with the web browser control if he
first transforms to HTML and has the web browser control display the HTML.
But what the original poster is after is simply passing on a string with
XML to the web browser control and have the web browser conrol
automatically apply its stylesheet for XML tree pretty printing. The
original poster is loading from disk to achieve that in which case he
does not need to run any transformation itself or need to use script to
document.write something.


--

Martin Honnen --- MVP XML
Re: Display XML in WebBrowser Control Dimitre Novatchev
9/28/2006 7:54:47 PM
Dave,
Thank you for the observed problem.

The fact is that this stylesheet was converted from the original non-XSLT
stylesheet used by IE.

It is very old and is accepted by MSXML3 (used by IE) and MSXML4.

The necessary corrections are:

1.

In
<xsl:template match="@*|@xmlns:*|@xmlns|@xml:*|@dt:*|@d2:*">

remove all "attributes" after the first:

<xsl:template match="@*">


2. For all <xsl-apply-templates> (there are 5-6 such) with a select
attribute that contains similar "ayttributes:, remove them.


One could use the stylesheet of the XPath Visualizer for Mozilla, which does
not contain such expressions.

Cheers,
Dimitre Novatchev

[quoted text, click to view]

Re: Display XML in WebBrowser Control Dimitre Novatchev
9/28/2006 8:20:11 PM
[quoted text, click to view]

He didn't say so in his original message -- only that he wanted to avoid
writing to a disk file.

Of course, he has to parse the string containing the xml document and to
perform an xslt transformation then feed the HTML result to the browser
control.


Cheers,
Dimitre Novatchev

[quoted text, click to view]

Re: Display XML in WebBrowser Control Webbert
9/29/2006 6:13:02 AM
I change the match from
<xsl:template match="@*|@xmlns:*|@xmlns|@xml:*|@dt:*|@d2:*" > <!--
xml:space="preserve" -->
to
<xsl:template match="@*" > <!-- xml:space="preserve" -->

and similar xsl:apply-templates from
<xsl:apply-templates select="@*|@xmlns:*|@xmlns|@xml:*|@dt:*|@d2:*"/>
<SPAN class="m">></SPAN></DIV>
to
<xsl:apply-templates select="@*"/> <SPAN class="m">></SPAN></DIV>


I added enable scripting for the transformer as well do to an execption
being generated.
XsltSettings xsltSettings = new XsltSettings( true, true );

XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load( @"..\..\Template\myDefaultss80.xsl", xsltSettings, null );
xslt.Transform( @"..\..\Data\authors.xml", @"..\..\Data\output.html" );

and I get an exception in this code
<msxsl:script implements-prefix="vxpathuser">
<![CDATA[
function xml(node)
{
return node(0).xml; //now();
}


An exception of type 'Microsoft.JScript.JScriptException' occurred in
Microsoft.JScript.dll but was not handled in user code. Additional
information: Error in the application.

JScriptException
----------------
Function expected


If I comment out the return statement everything works although I get no
data for the node

<authors xmlns:user="mynamespace">
<author>
<name idd="VH"></name>
<user2:name idd="VH"></user2:name>
<nationality></nationality>
</author>


If I remove all instances of vxpathuser:xml() from the following
<SPAN id="Selected" class="se"> <xsl:value-of
select="vxpathuser:xml(.)"/></SPAN>
to
<SPAN id="Selected" class="se"> <xsl:value-of select="."/></SPAN>

I get all the data but extra blank lines in the output.

I have been unable to find any information on vxpathuser:xml().
I would imagine that the problem I am experiencing has something to do with
my machine, but am unsure.


Machine Information
==========================
Windows XP SP2
MS IE v6.0.2900.2180.xpsp_sp2_gdr.050301-1519
MSXML 6.0 Parser v6.00.3883.8



Any thoughts are appreciated.
Dave

=================================


[quoted text, click to view]
Re: Display XML in WebBrowser Control Dimitre Novatchev
9/29/2006 7:16:36 AM
I see you want to transform this using .NET XslCompiledTransform

Please, provide an email address and I will send to you one of the newer
(and yet unpublished as part of XPath Visualizer) versions of this
stylesheet. I could post it here, but it is rather long and may not be of
interest to other people.

Cheers,
Dimitre Novatchev.

[quoted text, click to view]

Re: Display XML in WebBrowser Control Webbert
9/29/2006 12:26:01 PM
webbertsolutions@hotmail.com.REMOVE.THIS

[quoted text, click to view]
Re: Display XML in WebBrowser Control Webbert
10/9/2006 7:48:02 AM
Works great.
Much appreciated.

Cheers,
Dave


[quoted text, click to view]
AddThis Social Bookmark Button