By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,537 Members | 1,750 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,537 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Nov 11 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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

On Mon, 6 Oct 2003 11:36:59 +0200, Winston <wi***********@gmx.net> wrote:
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

Nov 11 '05 #2

P: n/a
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 [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:op**************@msnews.microsoft.com...
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

On Mon, 6 Oct 2003 11:36:59 +0200, Winston <wi***********@gmx.net> wrote:
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


Nov 11 '05 #3

P: n/a
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 [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:op**************@msnews.microsoft.com...
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

On Mon, 6 Oct 2003 11:36:59 +0200, Winston <wi***********@gmx.net> wrote:
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


Nov 11 '05 #4

P: n/a
On Mon, 6 Oct 2003 11:36:59 +0200, "Winston" <wi***********@gmx.net>
wrote:
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.

Nov 11 '05 #5

P: n/a
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-lis.../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" <jo********@hotmail.com> wrote in message
news:Oh*************@TK2MSFTNGP09.phx.gbl...
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 [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote in message news:op**************@msnews.microsoft.com...
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

On Mon, 6 Oct 2003 11:36:59 +0200, Winston <wi***********@gmx.net> wrote:
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



Nov 11 '05 #6

P: n/a
"Winston" <wi***********@gmx.net> wrote in message news:ur**************@tk2msftngp13.phx.gbl...
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-lis.../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
Nov 11 '05 #7

P: n/a
http://msdn.microsoft.com/library/de...th_hn_2uck.asp

--

Joe

"Winston" <wi***********@gmx.net> wrote in message
news:ur**************@tk2msftngp13.phx.gbl...
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-lis.../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" <jo********@hotmail.com> wrote in message
news:Oh*************@TK2MSFTNGP09.phx.gbl...
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 [.NET/C# MVP]" <ni**************@exisconsulting.com> wrote
in message news:op**************@msnews.microsoft.com...
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

On Mon, 6 Oct 2003 11:36:59 +0200, Winston <wi***********@gmx.net> wrote:
> 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
>
>




Nov 11 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.