Loading XML strings into a DHTML Active X Control
-
I have an MFC based dialog application that contains a DHTML ActiveX control. I want to be able to pass an XML string to the control and have the XML displayed in the control. Does anyone know if there is a way to do this? I have tried passing an XML string to the control using the CDHTMLEdit::SetDocumentHTML() method but it does not work. It will only correctly display HTML strings. Due to my lack of success with the DHTML control I decided to replace the control with the Microsoft Web Browser ActiveX control to see if I could load XML strings into this control. I eventually got this to work ok but only after saving the XML to a file on the harddrive and then calling CWebBrowser2::Navigate(), passing the Navigate method the name of the file just saved. Even though this works I would prefer to be able to pass the XML as a string straight into the control without having to save the xml to disk first. On the MSDN website there is some example code which shows how to load HTML content directly from a stream into the WebBrowser control. This does not work though with XML. Does anyone know why? Martin Hinchy
-
I have an MFC based dialog application that contains a DHTML ActiveX control. I want to be able to pass an XML string to the control and have the XML displayed in the control. Does anyone know if there is a way to do this? I have tried passing an XML string to the control using the CDHTMLEdit::SetDocumentHTML() method but it does not work. It will only correctly display HTML strings. Due to my lack of success with the DHTML control I decided to replace the control with the Microsoft Web Browser ActiveX control to see if I could load XML strings into this control. I eventually got this to work ok but only after saving the XML to a file on the harddrive and then calling CWebBrowser2::Navigate(), passing the Navigate method the name of the file just saved. Even though this works I would prefer to be able to pass the XML as a string straight into the control without having to save the xml to disk first. On the MSDN website there is some example code which shows how to load HTML content directly from a stream into the WebBrowser control. This does not work though with XML. Does anyone know why? Martin Hinchy
Here's probably the easiest way assuming you are using IE5.* Load the XML string into an MSXML IXMLDOMDocument object using the load or loadXML depending on your use. Then load the default style sheet for XML from the msxml.dll into another IXMLDOMDocument object using the load method and specifiying the url of : "res://msxml.dll/DEFAULTSS.XSL" Then do a transformNode on your XML document using the stylesheet. Then put the resulting transformation into your SetDocumentHTML method. If you don't think IE5 will be installed, then you can put the defaultss.XSL into your application as a resource and load it from your own component using the res prototcol. look for "Using the Default XSL Style Sheet in Your Application" in msdn which will have a link to get the default stylesheet that IE5 uses. -Erik