Viewing XML in AxSHDocVW
-
I'm trying to show XML that I get streamed to my app in a browser control. To test, I've dropped a control on a form and let the designer do the init work (BeginInit, misc. code, EndInit). Here's what I've added in my form's ctor :
object a = string.Empty; axWebBrowser1.Navigate( "about:blank", ref a, ref a, ref a, ref a ); string xml = "42"; ((IHTMLDocument2)axWebBrowser1.Document).body.innerHTML = xml;
The last line throws a NullReferenceException. I'm not sure why -- this code is supposed to work, right? Can someone pass on some advice on how to make this work or on the proper way to show XML in a browser control? Thanks! -
I'm trying to show XML that I get streamed to my app in a browser control. To test, I've dropped a control on a form and let the designer do the init work (BeginInit, misc. code, EndInit). Here's what I've added in my form's ctor :
object a = string.Empty; axWebBrowser1.Navigate( "about:blank", ref a, ref a, ref a, ref a ); string xml = "42"; ((IHTMLDocument2)axWebBrowser1.Document).body.innerHTML = xml;
The last line throws a NullReferenceException. I'm not sure why -- this code is supposed to work, right? Can someone pass on some advice on how to make this work or on the proper way to show XML in a browser control? Thanks!:confused: I believe several things are being confused here. To get it short, Internet Explorer shows xml content when it loads a document with application/xml mime type, and applies a default (unless specified) xslt stylesheet, producing the nice rendering anyone can see. You are quicker done by storing the stream to a local file, and call a Navigate2 to this local file. Unless you do this, there is no association between your xml stream and what Internet Explorer shows : remember an html document is made of html tags (rendering semantics), not xml tags.
-
:confused: I believe several things are being confused here. To get it short, Internet Explorer shows xml content when it loads a document with application/xml mime type, and applies a default (unless specified) xslt stylesheet, producing the nice rendering anyone can see. You are quicker done by storing the stream to a local file, and call a Navigate2 to this local file. Unless you do this, there is no association between your xml stream and what Internet Explorer shows : remember an html document is made of html tags (rendering semantics), not xml tags.
Is there a way to set the mime type on the IHTMLDocument2 object? I could have a ton of XML messages to display according to user selection -- having to save these as temp files or use one file as a temp writing space could be a pain. I could save some trouble if the mime type could be changed...is is possible?
-
Is there a way to set the mime type on the IHTMLDocument2 object? I could have a ton of XML messages to display according to user selection -- having to save these as temp files or use one file as a temp writing space could be a pain. I could save some trouble if the mime type could be changed...is is possible?
I am aware of only two ways to associate a mime type to a document, in order to render the document in Internet Explorer : - have a URI (local file, remote file) to play with, use Internet Explorer API to navigate to this URI - have a web server generate the appropriate mimetype for you. In your case, the web server would simply redirect the stream, only adding the appropriate http header to it. I am not aware of a successful way of changing the mimetype on-the-fly playing with the HTML Meta tag, of the form : <META HTTP-EQUIV="Content-Type" CONTENT="text/html">
-
I am aware of only two ways to associate a mime type to a document, in order to render the document in Internet Explorer : - have a URI (local file, remote file) to play with, use Internet Explorer API to navigate to this URI - have a web server generate the appropriate mimetype for you. In your case, the web server would simply redirect the stream, only adding the appropriate http header to it. I am not aware of a successful way of changing the mimetype on-the-fly playing with the HTML Meta tag, of the form : <META HTTP-EQUIV="Content-Type" CONTENT="text/html">
Yeah, playing around I see that the Type property is read-only. PutProperty on the AxWebBrowser doesn't seem to work either, but I can't find any docs on the valid data elements that can be passed to this method. Gotta love it when cool components like this go undocumented! I think I'll just resort to your first suggestion : stream to a file then load that file in Navigate.
-
Yeah, playing around I see that the Type property is read-only. PutProperty on the AxWebBrowser doesn't seem to work either, but I can't find any docs on the valid data elements that can be passed to this method. Gotta love it when cool components like this go undocumented! I think I'll just resort to your first suggestion : stream to a file then load that file in Navigate.
-
clickety[^] He loads the Xml content from a file, transforms it using a default xslt, and then writes the output html in the web browser. The sample itself is of no help, unless m_mond writes local files. The good news is that the .NET System.Xml namespace both can load a xml file or a stream. This provides the required tool.