DOM and MSXML

DOM and MSXML 

 

The DOM implementation is just one of the MSXML core services. The following diagram shows the tasks involved in parsing an XML document and presenting the information to an application or script.

The save method serializes the DOM tree.  
Modeling Documents as Node Trees 

 

The DOM provides you with an interface for loading, accessing, manipulating, and serializing XML documents. The DOM provides a representation of a complete XML document stored in memory, providing random access to the contents of the entire document. The DOM allows applications to rely on the logic provided by the MSXML parser to handle XML-based information, using its facilities rather than writing custom code to read and process XML.

When the MSXML parser loads an XML document into a DOM, it reads it from start to finish and creates a logical model of nodes from the structures and content within the XML document. The document itself is considered a single node that contains all of the other nodes, including a node representing the root element, which, in turn, contains all of the element, attribute, and text nodes in the document.

Example

The following XML document has a simple multi-tier structure.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="show_book.xsl"?>
<!DOCTYPE catalog [ 
<!NOTATION XLS PUBLIC "http://www.microsoft.com/office/excel/">
<!ELEMENT COLLECTION    (DATE? , BOOK+) >
<!ATTLIST COLLECTION
    xmlns:dt CDATA #FIXED "urn:schemas-microsoft-com:datatypes">
<!ELEMENT BOOK (TITLE, AUTHOR, PUBLISHER) >
<!ELEMENT DATE          (#PCDATA) >
<!ELEMENT TITLE         (#PCDATA)  >
<!ELEMENT AUTHOR        (#PCDATA)  >
<!ELEMENT PUBLISHER     (#PCDATA)  >
]>
<!--catalog last updated 2000-11-01-->
<catalog xmlns="http://www.example.com/catalog/">
  <book id="bk101">
     <author>&#71;ambardella, Matthew</author>
     <title>XML Developer's &#x47;uide</title>
     <genre>Computer</genre>
     <price>44.95</price>
     <publish_date>2000-10-01</publish_date>
     <description><![CDATA[An in-depth look at creating applications with XML, using <, >,]]> and &amp;.</description>
  </book>
  <book id="bk109">
     <author>Kress, Peter</author>
     <title>Paradox Lost</title>
     <genre>Science Fiction</genre>
     <price>6.95</price>
     <publish_date>2000-11-02</publish_date>
     <description>After an inadvertant trip through a Heisenberg Uncertainty Device, James Salway discovers the problems of being quantum.</description>
  </book>
</catalog>

After MSXML parsing, the top two levels of the node structure representing this document will look like this.

Parsed DOM tree

The topmost node is the document itself, which contains all of the other nodes. Immediately within the document are nodes representing the XML declaration, the style sheet processing instruction, the DOCTYPE declaration, and the root element for the document, in this case, catalog.

The catalog element contains the real content of the document, and its structure is shown below.

Parsed DOM tree

This part of the DOM contains element, attribute, text, and CDATA nodes. (The character references and built-in entities are converted to ordinary text by the parser, but the CDATA section has its own node.)

XML DOM Objects/Interfaces 

 

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.

XML DOM Implemented Objects/Interfaces

The following table represents implementations of other XML DOM interfaces.

IServerXMLHTTPRequest/ServerXMLHTTP

Provides methods and properties that enable you to establish an HTTP connection between files or objects on different Web servers. This interface is derived from IXMLHTTPRequest.

IXMLDOMAttribute

Represents an attribute.

IXMLDOMCDATASection

Quotes or escapes blocks of text so that text is not interpreted as markup language.

IXMLDOMCharacterData

Provides text manipulation methods that are used by several objects.

IXMLDOMComment

Represents the content of an XML comment.

IXMLDOMDocumentFragment

Represents a lightweight object that is useful for tree insertion operations.

IXMLDOMDocumentType

Contains information associated with the document type declaration.

IXMLDOMElement

Represents the element.

IXMLDOMEntity

Represents a parsed or unparsed entity in the XML document.

IXMLDOMEntityReference

Represents an entity reference node.

IXMLDOMImplementation

Provides methods that are independent of any particular instance of the document object model.

IXMLDOMNotation

Contains a notation declared in the DTD or schema.

IXMLDOMProcessingInstruction

Represents a processing instruction. XML defines this instruction to keep processor-specific information in the text of the document.

XMLSchemaCache

Represents a set of namespace URIs.

IXMLDOMSchemaCollection/XMLSchemaCache

Represents a SchemaCache object.

IXMLDOMSchemaCollection2/XMLSchemaCache

An extension of IXMLDOMSchemaCollection.

IXMLDOMSelection

Represents a list of nodes that match an XPath expression.

IXMLDOMText

Represents the text content of an element or attribute.

IXSLProcessor

Used for performing transformations with cached XSL templates.

IXSLTemplate

Represents a cached XSL style sheet.

For a list of all valid node types, see XML DOM Enumerated Constants.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值