473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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

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
7 13964
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
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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ram | last post by:
I have a user control uc (with a dropdownlist uc_dd) that I dynamically add to a pane on a button_click. this pane is hosted on the winform. now when I add two instances of the user control...
7
by: Winston | last post by:
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...
7
by: John | last post by:
Hi, Is there any control (free) that has same functionality as IE to display the XML document without having to create a physical file? if using Webbrowser control (ActiveX control) I have to...
6
by: Chris | last post by:
I have a winform base class in which I dynamically set a web reference Url: myService.Url = <WebServer> + "MyService.asmx"; where <WebServer> is pulled from my App.config file. There is no...
0
by: nobody | last post by:
I am running Microsoft's example of a windows form in aspx. http://msdn.microsoft.com/msdnmag/issues/02/01/UserCtrl/default.aspx The only way I can get the example to run is by opening up the...
3
by: VB Programmer | last post by:
I have created a custom control in vb.net. How do I show 10 of them (vertical stack) on a new form when it loads? Thanks!
2
by: sobmir | last post by:
A I'm new to c# and I came from c++ also. I want to create dynamicaly winform to get some data. I create a array of object as a description of variable which I want to get. I pass this array to a...
6
by: crazyjh | last post by:
hello i want to add some controls in according of the time. but when the time change, i call the method again to add controls again,No effect! i think maybe i should unload the controls adding...
5
by: Andrus | last post by:
I have database containing translations. I'm creating VS 2005 WinForms application which should use this database to translate menu items to user language. I replaced lines in myform.designer.cs...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.