• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

MsXml DOM对象与接口

VC/MFC/Windows 弦苦 1507次浏览 0个评论

This part of the XML Document Object Model (DOM) reference describes the programming object syntax. The first table lists the core objects/interfaces. The second table lists the implemented objects/interfaces.

XML DOM Core Objects/Interfaces

The following objects/interfaces represent implementations of the XML DOM core objects/interfaces. The objects/interfaces include Microsoft extensions to support the following items and operations: namespaces, data types, XML schemas, Extensible Stylesheet Language (XSL), XSL Transformations (XSLT) operations, asynchronous loading, and the saving of documents.

IXMLDOMDocument/DOMDocument

Represents the top node of the XML DOM tree.

IXMLDOMDocument2

An extension of DOMDocument. This extension supports schema caching and runtime validation, and provides a way to switch on XML Path Language (XPath) support.

IXMLDOMNamedNodeMap

Enables iteration and access, by name, to the collection of attributes. IXMLDOMNamedNodeMapincludes support for namespaces.

IXMLDOMNode

Represents a single node in the document tree. IXMLDOMNode is the base interface for accessing data in the XML object model. This interface includes support for data types, namespaces, document type definitions (DTDs), and XML schemas.

IXMLDOMNodeList

Enables iteration and indexed access operations on the live collection of IXMLDOMNode.

IXMLDOMParseError

Returns detailed information about the last error, including the error number, the line number, the character position, and a text description.

IXMLHTTPRequest

Provides client-side protocol support for communication with HTTP servers.

 

VC程序中,导入MsXml4解析器代码如下:

#import <msxml4.dll> // C:/WINDOWS/system32/msxml4.dll

using namespace MSXML2;

以上自动方式导入msxml4.dll,编译后将会在工程目录下的debug/release文件夹下生成头文件msxml4.tlh和实现文件msxml4.tli

msxml4.tli : Typelib Generated C/C++ Inline File

// compiler-generated

// Wrapper implementations for Win32 type library msxml4.dll

msxml4.tlh : Typelib Generated C/C++ Header

// compiler-generated file

// C++ source equivalent of Win32 type library msxml4.dll

关于接口的声明参考msxml4.tlh文件,以下为MsXml Parser中主要接口示意图。关于各接口的详细说明及使用示例,请参考MSDN

 

MsXml DOM对象与接口

 

MSXML DOM Objects/Interfaces示意图

 

IXMLDOMDocument属性和方法除继承IXMLDOMNode外,有以下重要扩充:

VARIANT_BOOL load (const _variant_t & xmlSource ); // 从指定路径加载xml文档

VARIANT_BOOL loadXML (_bstr_t bstrXML ); // 加载具有xml格式的字符串

HRESULT save (const _variant_t & destination ); // xml文档保存到指定路径

 

// 获取指定名称的节点(集),类似IXMLDOMNode.selectNodes

IXMLDOMNodeListPtr getElementsByTagName (_bstr_t tagName );

 

// 以下为访存根节点元素documentElement的接口

IXMLDOMElementPtr GetdocumentElement ( );

void PutRefdocumentElement ( struct IXMLDOMElement * DOMElement );

 

// 以下为创建节点元素的接口

IXMLDOMElementPtr createElement ( _bstr_t tagName );

IXMLDOMTextPtr createTextNode ( _bstr_t data );

IXMLDOMCommentPtr createComment (_bstr_t data );

IXMLDOMAttributePtr createAttribute ( _bstr_t name );

IXMLDOMNodePtr createNode ( const _variant_t & type,

_bstr_t name,

_bstr_t namespaceURI );

 

继承自IXMLDOMNode的其他重要接口如下:

1IXMLDOMDocument:代表整个XML文档——切皆为节点!

2IXMLDOMProcessingInstructionXML文档声明,包括version属性encoding属性和encoding属性。

3IXMLDOMElement:代表节点元素。

4IXMLDOMAttribute:代表节点属性,属性本身也是节点。

5IXMLDOMComment:代表注释节点。此为二级继承接口。

 

参考

http://msdn.microsoft.com/en-us/library/ms760218(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms761386(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms767664(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms767713(VS.85).aspx

http://msdn.microsoft.com/en-us/library/ms757878(VS.85).aspx


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明MsXml DOM对象与接口
喜欢 (0)

您必须 登录 才能发表评论!

加载中……