How to use IE to display XML dynamically in an WinForm?

W

Winston

Hi,
I want to use the Webbrowser Control (the Internet Explorer Control) to
display an XML-structure within a C# WinForm.
The way the IE displays a XML-file in its native form is exactly what I need
(as tree structure with plus/minus).

This works great as long as I load the XML to display from a file with the
Navigate2-method of the control.

But my XML comes not from a file but is created dynamically during runtime.
When I feed the document-object of the IE-control with my generated XML,
unfortunately the IE control displays my XML as plain text and not in
XML-mode.

Does anyone know how to tell the IE with C# that the given string has to be
displayed as a XML document?

Any help appreciated,
Winston
 
N

Nicholas Paldino [.NET/C# MVP]

Winston,

There is an easy way, and a a few hard ways to do this. The easy way would be to save your XML to a temporary file and then navigate to that file.

The first hard way would be to define the IPersistMemory interface in your code. This is a COM interface that is part of the persistence framework that COM exposed. It allows you to load content from an area in memory. If you get this interface, then you can cast the HTML document to this interface and then call the Load method. Content type is determined by "sniffing" the content, as opposed to headers from a server.

The definitive way would be to create an implementation of the IMoniker interface and then control the information that is accessed by the HTML document when loading. With the implementation of IMoniker, you can control what the HTML document gets, so you can set the content type of the document to "text/xml" explicitly, which will trigger the display that you wish. For this, you would have to define the IMoniker and IPersistMoniker interfaces.

Hope this helps.
 
J

Joe Fawcett

Alternatively transform the source xml using IE's default stylesheet and
then use your current method to display the result. Default stylesheet at:
res://msxml3.dll/DEFAULTSS.xsl
--

Joe

Nicholas Paldino said:
Winston,

There is an easy way, and a a few hard ways to do this. The easy way
would be to save your XML to a temporary file and then navigate to that
file.
The first hard way would be to define the IPersistMemory interface in your
code. This is a COM interface that is part of the persistence framework
that COM exposed. It allows you to load content from an area in memory. If
you get this interface, then you can cast the HTML document to this
interface and then call the Load method. Content type is determined by
"sniffing" the content, as opposed to headers from a server.
The definitive way would be to create an implementation of the IMoniker
interface and then control the information that is accessed by the HTML
document when loading. With the implementation of IMoniker, you can control
what the HTML document gets, so you can set the content type of the document
to "text/xml" explicitly, which will trigger the display that you wish. For
this, you would have to define the IMoniker and IPersistMoniker interfaces.
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- nick(d0t)paldino=At-exisconsulting'dot|com

Hi,
I want to use the Webbrowser Control (the Internet Explorer Control) to
display an XML-structure within a C# WinForm.
The way the IE displays a XML-file in its native form is exactly what I need
(as tree structure with plus/minus).

This works great as long as I load the XML to display from a file with the
Navigate2-method of the control.

But my XML comes not from a file but is created dynamically during runtime.
When I feed the document-object of the IE-control with my generated XML,
unfortunately the IE control displays my XML as plain text and not in
XML-mode.

Does anyone know how to tell the IE with C# that the given string has to be
displayed as a XML document?

Any help appreciated,
Winston
 
W

Winston

Hi Nicholas,
that sounds very good. I like to try the way with the IPersistMemory
interface but I don't know which reference I have to add in my project to
get access to that interface.
Can you help?

Winston

Nicholas Paldino said:
Winston,

There is an easy way, and a a few hard ways to do this. The easy way
would be to save your XML to a temporary file and then navigate to that
file.
The first hard way would be to define the IPersistMemory interface in your
code. This is a COM interface that is part of the persistence framework
that COM exposed. It allows you to load content from an area in memory. If
you get this interface, then you can cast the HTML document to this
interface and then call the Load method. Content type is determined by
"sniffing" the content, as opposed to headers from a server.
The definitive way would be to create an implementation of the IMoniker
interface and then control the information that is accessed by the HTML
document when loading. With the implementation of IMoniker, you can control
what the HTML document gets, so you can set the content type of the document
to "text/xml" explicitly, which will trigger the display that you wish. For
this, you would have to define the IMoniker and IPersistMoniker interfaces.
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- nick(d0t)paldino=At-exisconsulting'dot|com

Hi,
I want to use the Webbrowser Control (the Internet Explorer Control) to
display an XML-structure within a C# WinForm.
The way the IE displays a XML-file in its native form is exactly what I need
(as tree structure with plus/minus).

This works great as long as I load the XML to display from a file with the
Navigate2-method of the control.

But my XML comes not from a file but is created dynamically during runtime.
When I feed the document-object of the IE-control with my generated XML,
unfortunately the IE control displays my XML as plain text and not in
XML-mode.

Does anyone know how to tell the IE with C# that the given string has to be
displayed as a XML document?

Any help appreciated,
Winston
 
J

Jekke, Just Jekke

Hi,
I want to use the Webbrowser Control (the Internet Explorer Control) to
display an XML-structure within a C# WinForm.
The way the IE displays a XML-file in its native form is exactly what I need
(as tree structure with plus/minus).

This works great as long as I load the XML to display from a file with the
Navigate2-method of the control.

But my XML comes not from a file but is created dynamically during runtime.
When I feed the document-object of the IE-control with my generated XML,
unfortunately the IE control displays my XML as plain text and not in
XML-mode.

Does anyone know how to tell the IE with C# that the given string has to be
displayed as a XML document?

A quick and dirty way to do this is to temporarily persist your XML to
file, then load it from the file into your reader.

I do not know if there's a more elegant solution.
 
W

Winston

I solved it with your help and a little workaround.
Loading res://msxml3.dll/DEFAULTSS.xsl into my XMLDocument-Object didn't
work. I guess that those res:// files can only be read by the IE itself.
I found a slightly modified version of this Default-XSL at
http://www.biglist.com/lists/xsl-list/archives/200003/msg00769.html.
After fixing some typing errors I saved it into a file.
Now I load that XSL from disk, and transform my XML-string with this XSL
into HTML.
When I feed this into the IE-control it looks like the way the IE does it.

Thanks for your help,
Winston

Joe Fawcett said:
Alternatively transform the source xml using IE's default stylesheet and
then use your current method to display the result. Default stylesheet at:
res://msxml3.dll/DEFAULTSS.xsl
--

Joe

in message news:blush:[email protected]...
Winston,

There is an easy way, and a a few hard ways to do this. The easy way
would be to save your XML to a temporary file and then navigate to that
file.
The first hard way would be to define the IPersistMemory interface in
your
code. This is a COM interface that is part of the persistence framework
that COM exposed. It allows you to load content from an area in memory. If
you get this interface, then you can cast the HTML document to this
interface and then call the Load method. Content type is determined by
"sniffing" the content, as opposed to headers from a server.
The definitive way would be to create an implementation of the IMoniker
interface and then control the information that is accessed by the HTML
document when loading. With the implementation of IMoniker, you can control
what the HTML document gets, so you can set the content type of the document
to "text/xml" explicitly, which will trigger the display that you wish. For
this, you would have to define the IMoniker and IPersistMoniker interfaces.
Hope this helps.
 
D

Dimitre Novatchev

Winston said:
I solved it with your help and a little workaround.
Loading res://msxml3.dll/DEFAULTSS.xsl into my XMLDocument-Object didn't
work. I guess that those res:// files can only be read by the IE itself.
I found a slightly modified version of this Default-XSL at
http://www.biglist.com/lists/xsl-list/archives/200003/msg00769.html.
After fixing some typing errors I saved it into a file.
Now I load that XSL from disk, and transform my XML-string with this XSL
into HTML.
When I feed this into the IE-control it looks like the way the IE does it.

Thanks for your help,
Winston


This transformation produces a display of non-well-formed xml in the
following two general cases:

1. The original xml document contains namespace declarations. In
this case
there are no namespace declarations displayed.

2. The original document contains (correctly) escaped ampersand. In
this case
unescaped ampersand is displayed.


The stylesheets used by the XPath Visualizer (for IE and for Mozilla)
do not have these flaws.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL
 
J

Joe Fawcett

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xml_mth_hn_2uck.asp

--

Joe

Winston said:
I solved it with your help and a little workaround.
Loading res://msxml3.dll/DEFAULTSS.xsl into my XMLDocument-Object didn't
work. I guess that those res:// files can only be read by the IE itself.
I found a slightly modified version of this Default-XSL at
http://www.biglist.com/lists/xsl-list/archives/200003/msg00769.html.
After fixing some typing errors I saved it into a file.
Now I load that XSL from disk, and transform my XML-string with this XSL
into HTML.
When I feed this into the IE-control it looks like the way the IE does it.

Thanks for your help,
Winston

Joe Fawcett said:
Alternatively transform the source xml using IE's default stylesheet and
then use your current method to display the result. Default stylesheet at:
res://msxml3.dll/DEFAULTSS.xsl
--

Joe

in message news:blush:[email protected]...
Winston,

There is an easy way, and a a few hard ways to do this. The easy way
would be to save your XML to a temporary file and then navigate to that
file.
The first hard way would be to define the IPersistMemory interface in
your
code. This is a COM interface that is part of the persistence framework
that COM exposed. It allows you to load content from an area in memory. If
you get this interface, then you can cast the HTML document to this
interface and then call the Load method. Content type is determined by
"sniffing" the content, as opposed to headers from a server.
The definitive way would be to create an implementation of the
IMoniker
interface and then control the information that is accessed by the HTML
document when loading. With the implementation of IMoniker, you can control
what the HTML document gets, so you can set the content type of the document
to "text/xml" explicitly, which will trigger the display that you wish. For
this, you would have to define the IMoniker and IPersistMoniker interfaces.
Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- nick(d0t)paldino=At-exisconsulting'dot|com

what
I with
the
has
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top