可以,我以前做过类似的应用 主要用的接口是IXMLDOMDocumnet2,IXMLDOMNode,...,你最好装个.net msdn,那里有关于XMLDOM SDK的详细手册 由于我是用VB Delphi 做的,显示用的是webbrowser ctrl ,没用过CDhtmlDialog,不知道怎么操作,不过只要CDhtmlDialog能得到IHtmlDocument2 or istream or 有write HTML 之类的方法就应该行 由于涉及的内容比较多,我们可以以一点一大的讨论
zhp80,您好, 现在主要是想从Webbrowser中得到IXMLDomDocument之类的接口,但不知怎么才能正确的得到它.我在VB中这样写,运行时报错,说类型不配佩 dim a as IXMLDOMDocument set a=webbrowser1.Document
dim obj as object set obj=createobject("xml2.xmldocument") obj.add...... 等等代码就可以使用了
你这样子想好像是不行的 一般的HTML无法成为XML文档,因为XML要求的格式很严格 你可以写数据到XML文档中啊, 然后在后台把数据写到服器端的一个目录中去, 同目录中放上那个要使用的xsl文件, 然后你在xml文档中增加xsl文件的路径说明,不就OK了吗?? Re-------------------在VB中这样写,运行时报错,说类型不配佩 dim a as IXMLDOMDocument set a=webbrowser1.Document
dim a as IXMLDOMDocument set a=webbrowser1.Document 这种使用方法我没用过,估计CoClass MSHTML.HTMLDocument 不支持MSXML2.IXMLDOMDocument 你可以用QueryInterface试一下,从VB的现象看多半是不行的 不过MSHTML.HTMLDocument 是支持IStream的,你可以从HTMLDocument2转换成IStream,再用XMLDOM处理 另外,为什么要从webbrowser1 中取MSHTML.HTMLDocument 呢?而不向webbrowser1.Document写呢?
改MFCIE示例的mfcieVw.cpp #include "stdafx.h" #include "mfcie.h" #include "MainFrm.h"#include "mfcieDoc.h" #include "mfcieVw.h"#pragma warning(disable : 4192) #pragma warning(disable : 4049) #pragma warning(disable : 4146) #import <mshtml.tlb> #import <msxml4.dll> #pragma warning(default: 4192) #pragma warning(default: 4049) #pragma warning(default: 4146) // Include Microsoft HIML definitions...#include <dispex.h>//You may derive a class from CComModule and use it if you want to override //something, but do not change the name of _Module #include <atlbase.h>//for atlcom.h extern CComModule _Module;//for atlbase.h #include <atlcom.h>//for OLE2T…… END_MESSAGE_MAP()BEGIN_EVENTSINK_MAP(CMfcieView, CHtmlView) ON_EVENT(CMfcieView, AFX_IDW_PANE_FIRST, 259 /* DocumentComplete */, DocumentComplete, VTS_DISPATCH VTS_PVARIANT) END_EVENTSINK_MAP()///////////////////////////////////////////////////////////////////////////// // CMfcieView construction/destruction…… //END OF MFC MEMORY LEAK BUG FIXvoid CMfcieView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL) { ASSERT(V_VT(URL) == VT_BSTR); IDispatchPtr spDisp; HRESULT hr; hr = m_pBrowserApp->QueryInterface(IID_IDispatch, (void**) &spDisp); // Is the IDispatch* passed to us for the top-level window ? if (pDisp == spDisp) { MSHTML::IHTMLDocument2Ptr spDoc; // Get the active document spDoc = GetHtmlDocument(); if ( spDoc ) { MSHTML::IHTMLWindow2Ptr spWin; // Get the top-level window spDisp = spDoc->Script; spWin = spDisp; if ( spWin ) { // Get the document spDoc = spWin->document; if ( spDoc ) { IDispatchExPtr spDispEx; // Get the document's IDispatchEx spDoc->QueryInterface( IID_IDispatchEx, (void**)&spDispEx ); if ( spDispEx ) { _bstr_t bstrName("XMLDocument"); DISPID dispid; // Get the XMLDocument expando property spDispEx->GetDispID( bstrName, fdexNameCaseSensitive, &dispid ); if ( SUCCEEDED(hr) && dispid != DISPID_UNKNOWN ) { VARIANT var; DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0}; // Get the XMLDocument value hr = spDispEx->Invoke( dispid, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET, &dpNoArgs, &var, NULL, NULL ); if ( SUCCEEDED(hr) && var.vt == VT_DISPATCH ) { MSXML2::IXMLDOMDocument* pXMLDoc=NULL; // Get the IXMLDOMDocument interface var.pdispVal->QueryInterface( IID_IXMLDOMDocument, (void**)&pXMLDoc ); VariantClear( &var ); if ( pXMLDoc ) { // Get the root element MSXML2::IXMLDOMElement* pXMLElem=NULL; pXMLDoc->get_documentElement( &pXMLElem ); if ( pXMLElem ) { BSTR bstr; USES_CONVERSION; // Get/display the tag name pXMLElem->get_tagName( &bstr ); AfxMessageBox( OLE2T(bstr) ); pXMLElem->Release(); } pXMLDoc->Release(); } } } } } } } } } //end new code
import C:\WINNT\System32\msxml3.dll
import C:\WINNT\system32\mshtml.tlb
主要用的接口是IXMLDOMDocumnet2,IXMLDOMNode,...,你最好装个.net msdn,那里有关于XMLDOM SDK的详细手册
由于我是用VB Delphi 做的,显示用的是webbrowser ctrl ,没用过CDhtmlDialog,不知道怎么操作,不过只要CDhtmlDialog能得到IHtmlDocument2 or istream or 有write HTML 之类的方法就应该行
由于涉及的内容比较多,我们可以以一点一大的讨论
现在主要是想从Webbrowser中得到IXMLDomDocument之类的接口,但不知怎么才能正确的得到它.我在VB中这样写,运行时报错,说类型不配佩
dim a as IXMLDOMDocument
set a=webbrowser1.Document
set obj=createobject("xml2.xmldocument")
obj.add......
等等代码就可以使用了
一般的HTML无法成为XML文档,因为XML要求的格式很严格
你可以写数据到XML文档中啊,
然后在后台把数据写到服器端的一个目录中去,
同目录中放上那个要使用的xsl文件,
然后你在xml文档中增加xsl文件的路径说明,不就OK了吗??
Re-------------------在VB中这样写,运行时报错,说类型不配佩
dim a as IXMLDOMDocument
set a=webbrowser1.Document
set a=webbrowser1.Document
这种使用方法我没用过,估计CoClass MSHTML.HTMLDocument 不支持MSXML2.IXMLDOMDocument
你可以用QueryInterface试一下,从VB的现象看多半是不行的
不过MSHTML.HTMLDocument 是支持IStream的,你可以从HTMLDocument2转换成IStream,再用XMLDOM处理
另外,为什么要从webbrowser1 中取MSHTML.HTMLDocument 呢?而不向webbrowser1.Document写呢?
#include "stdafx.h"
#include "mfcie.h"
#include "MainFrm.h"#include "mfcieDoc.h"
#include "mfcieVw.h"#pragma warning(disable : 4192)
#pragma warning(disable : 4049)
#pragma warning(disable : 4146)
#import <mshtml.tlb>
#import <msxml4.dll>
#pragma warning(default: 4192)
#pragma warning(default: 4049)
#pragma warning(default: 4146)
// Include Microsoft HIML definitions...#include <dispex.h>//You may derive a class from CComModule and use it if you want to override
//something, but do not change the name of _Module
#include <atlbase.h>//for atlcom.h
extern CComModule _Module;//for atlbase.h
#include <atlcom.h>//for OLE2T……
END_MESSAGE_MAP()BEGIN_EVENTSINK_MAP(CMfcieView, CHtmlView)
ON_EVENT(CMfcieView, AFX_IDW_PANE_FIRST, 259 /* DocumentComplete */, DocumentComplete, VTS_DISPATCH VTS_PVARIANT)
END_EVENTSINK_MAP()/////////////////////////////////////////////////////////////////////////////
// CMfcieView construction/destruction……
//END OF MFC MEMORY LEAK BUG FIXvoid CMfcieView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
ASSERT(V_VT(URL) == VT_BSTR);
IDispatchPtr spDisp;
HRESULT hr; hr = m_pBrowserApp->QueryInterface(IID_IDispatch, (void**) &spDisp);
// Is the IDispatch* passed to us for the top-level window ?
if (pDisp == spDisp)
{
MSHTML::IHTMLDocument2Ptr spDoc; // Get the active document
spDoc = GetHtmlDocument();
if ( spDoc )
{
MSHTML::IHTMLWindow2Ptr spWin; // Get the top-level window
spDisp = spDoc->Script;
spWin = spDisp;
if ( spWin )
{
// Get the document
spDoc = spWin->document;
if ( spDoc )
{
IDispatchExPtr spDispEx; // Get the document's IDispatchEx
spDoc->QueryInterface( IID_IDispatchEx,
(void**)&spDispEx );
if ( spDispEx )
{
_bstr_t bstrName("XMLDocument");
DISPID dispid; // Get the XMLDocument expando property
spDispEx->GetDispID( bstrName,
fdexNameCaseSensitive,
&dispid );
if ( SUCCEEDED(hr) && dispid != DISPID_UNKNOWN )
{
VARIANT var;
DISPPARAMS dpNoArgs = {NULL, NULL, 0, 0}; // Get the XMLDocument value
hr = spDispEx->Invoke( dispid,
IID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_PROPERTYGET,
&dpNoArgs,
&var,
NULL,
NULL );
if ( SUCCEEDED(hr) && var.vt == VT_DISPATCH )
{
MSXML2::IXMLDOMDocument* pXMLDoc=NULL; // Get the IXMLDOMDocument interface
var.pdispVal->QueryInterface(
IID_IXMLDOMDocument,
(void**)&pXMLDoc );
VariantClear( &var );
if ( pXMLDoc )
{
// Get the root element
MSXML2::IXMLDOMElement* pXMLElem=NULL; pXMLDoc->get_documentElement( &pXMLElem );
if ( pXMLElem )
{
BSTR bstr;
USES_CONVERSION; // Get/display the tag name
pXMLElem->get_tagName( &bstr );
AfxMessageBox( OLE2T(bstr) );
pXMLElem->Release();
}
pXMLDoc->Release();
}
}
}
}
}
}
}
}
}
//end new code