Microsoft's MSXML parser read an XML document and then parsing its content to an abstract information container called node (NODES). These nodes represent the structure and content of the document, and allow the application to read and operate the information in the document without the semantics of the XML known. After a document is parsed, its node can be browsed at any time without having to maintain a certain order. For developers, the most important programming object is DomDocument. DomDocument objects allow browsing, query, and modifying the contents and structures of XML documents, and each of the next objects can be collected, which can collect information about the object instance, the value of the object. And navigate to other objects of the tree. Msxml.dll included with the main COM interfaces: (1) DomDocument DomDocument object is the foundation of XML DOM, you can use the properties and methods it exposed to allow you to browse, query, and modify the contents and structure of the XML document. DomDocument represents the top layer node of the tree. It implements all basic methods for the DOM document and provides additional member functions to support XSL and XSLT. It creates a document object, all other objects can be obtained and created from this document object. (2) ixmldomnodeixmldomnode is the basic objects, elements, properties, comments, process instructions, or other document components in the Document Object Model (DOM), can be considered ixmldomnode, in fact, the DomDocument object itself is also an IXMLDomnode object. (3) ixmldomnodelist ixmldomnodelist is actually a collection of nodes, and the increase in nodes, deletions, and variations can be reflected immediately in the collection, and all nodes can be traversed through the "for ... next" structure. (4) The IXMLDompivalRROR IXMLDompivalError interface is used to return detailed information in the parsed process, including error numbers, line numbers, character positions, and text descriptions. The following is mainly description of the creation process of a DomDocument object, where the process of creating a document object is described with a VC description. HRESULT HR; IXMLDOMDOCUMENT * PXMLDoc; ixmldomnode * pxdn; hr = coinitialize (null); File: // COM initialization File: // Gets Pointer PXMLDOC for the IXmldomDocument interface. HR = COCREATEINSTANCE (CLSID_DOM Document, NULL, CLSCTX_INPPROC_SERVER, IID_IXMLDOMDOCUMENT, (Void **) & pxmldoc); File: // Gets Pointer PXDN about the IXMLDomnode interface. HR = PXMLDOC-> QueryInterface (IID_ixmldomnode, (void **) & pxdn); During the MSXML parser, we can use the CreateElement method in the document to create a node to load and save an XML file. With the LOAD or the LOADXML method, you can load an XML document from a specified URL. Load (loadXML) method has two parameters: the first parameter XMLSource indicates that the document that needs to be parsed, and the second parameter Issuccessful indicates whether the document load is successful. The Save method is used to save the document to a specified location. The Save method has a parameter Destination to indicate the type of object that needs to be saved, and the object can be a file, an ASP Response method, an XML document object, or a customer object that supports persistent save (persistence).
Below is a simple example of the Save method (see http://www.swm.com.cn/swm/200101/ using MSXML). At the same time, in the parsing process, we need to get and set the resolution flag. With different parsing signs, we may parse an XML document in different ways. The XML standard allows the parser to verify or do not verify the document, allowing the parsing process of the document to skip the extraction of external resources. In addition, you may set the flag to indicate whether you want to remove excess space from the document. In order to achieve this, the DomDocument object exposes the following attributes, allowing users to change the behavior of the parser when running: (1) Async (two methods relative to C , respectively, Get_Aasync and PUT_ASYNC) (2) ValidateonParse Compared with C is two methods, Get_Validate OnParse and Put_ValidateonParse, respectively, respectively, respectively, respectivelyxternals (two methods relative to C , which are Get_ Resolve Externals and Put_Resolveexternals) (4) PersercVewhitespace (two ways relative to C , respectively Each property can be accepted or returned for each property for GET_ PERSER CVEWHITESPACE and PUT_ERSERCVE Whitespace. The value of the default, anync, validateonparse, resolveexternals is true, and the value of the PERSERVEWHITESPACE is related to the setting of the XML document. If the XML document is set, this value is false. At the same time, some information on and document information can be collected during the document parsing process, in fact, the following information can be obtained during the document parsing process: (1) DOCTYPE: actually and DTD files used to define document formats. If the XML document does not have a related DTD document, it returns NULL. (2) Implementation: Indicates the implementation of the document, is actually used to point out the version of the XML supported by the current document. (3) ParseError: The error that happened during the parsing process. (4) ReadyState: Represents the status information of the XML document, ReadyState is an important role of asynchronously using Microsoft XML parsers to improve performance. When you load an XML document, your program may need to check resolution. The state, MSXML provides four states, which are being status, state, and are parsing and parsing. (5) URL (Uniform Resource Location): The case of the URL of the XML document that is being loaded and parsed. Note that if the document is built in memory, this property returns a null value. After obtaining the document tree structure, we can manipulate each node in the tree, which can get the nodes in the tree through two methods, respectively, NodeFromid and getElementsBytagName. NodeFromid includes two parameters, the first parameter IDString is used to represent the ID value, the second parameter node returns the interface pointer to the Node node that matches the ID. Note According to the technical requirements of XML, the ID value in each XML document must be unique, and one element is only associated with one ID.