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.
Represents the top node of the XML DOM tree. | |
An extension of DOMDocument. This extension supports schema caching and runtime validation, and provides a way to switch on XML Path Language (XPath) support. | |
Enables iteration and access, by name, to the collection of attributes. IXMLDOMNamedNodeMapincludes support for namespaces. | |
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. | |
Enables iteration and indexed access operations on the live collection of IXMLDOMNode. | |
Returns detailed information about the last error, including the error number, the line number, the character position, and a text description. | |
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 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的其他重要接口如下:
(1)IXMLDOMDocument:代表整个XML文档——切皆为节点!
(2)IXMLDOMProcessingInstruction:XML文档声明,包括version属性,encoding属性和encoding属性。
(3)IXMLDOMElement:代表节点元素。
(4)IXMLDOMAttribute:代表节点属性,属性本身也是节点。
(5)IXMLDOMComment:代表注释节点。此为二级继承接口。
参考:
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