Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Viewing XML in AxSHDocVW

Viewing XML in AxSHDocVW

Scheduled Pinned Locked Moved C#
xmltutorialquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    m_mond
    wrote on last edited by
    #1

    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!

    S 1 Reply Last reply
    0
    • M m_mond

      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!

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      :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.

      M 1 Reply Last reply
      0
      • S Stephane Rodriguez

        :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.

        M Offline
        M Offline
        m_mond
        wrote on last edited by
        #3

        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?

        S 1 Reply Last reply
        0
        • M m_mond

          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?

          S Offline
          S Offline
          Stephane Rodriguez
          wrote on last edited by
          #4

          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">

          M 1 Reply Last reply
          0
          • S Stephane Rodriguez

            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">

            M Offline
            M Offline
            m_mond
            wrote on last edited by
            #5

            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.

            L 1 Reply Last reply
            0
            • M m_mond

              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.

              L Offline
              L Offline
              leppie
              wrote on last edited by
              #6

              There some VB.NET (ouch) code (XMLViewer) on GotDotNet just posted last week doing what you want to do, it seems alot easier to work with VB.NET with these HTML interfaces. I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

              S 1 Reply Last reply
              0
              • L leppie

                There some VB.NET (ouch) code (XMLViewer) on GotDotNet just posted last week doing what you want to do, it seems alot easier to work with VB.NET with these HTML interfaces. I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02

                S Offline
                S Offline
                Stephane Rodriguez
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups