VC ++ uses MSXML parsing XML documentation

xiaoxiao2021-03-06  104

Article Title: VC Using MSXML Analysis XML Document Representative: Hou Xiaoyun Place: LOSE_WENT Release Type: Reprint Release Date: 2004-04-23 Today Views: 11 Total View: 2140

Abstract: XML document is a popular structured document form in recent years, and its main use is not only applicable to developing web pages, and there is also a wide range of applications in other occasions. This article mainly introduces the analysis of XML documents when developing applications with VC . Keywords: XML HTML SGML COM DOM DOM 1, XML Introduction XML (Xtensible Markup Language, the development of extended tag language) originated in 1996. At that time, the publishing biliary giants and Web industry sources have been discussed, proposes suggestions for creating SGML (Standard Generalized Markup Language, That is, standard universal identity language) subset (HML). The subset is dedicated to the web with all advanced features of expandable (or expandable), and can utilize all advanced features of the structured marker language, but abandon the complexity of SGML. The first draft of the XML specification was released shortly after November 1996, and the first XML parser in January 1997 was available. Subsequently, XML applications and new specifications and parsers appear. HTML (Hypertext Markup Language) is a marker language for the development web page that everyone is familiar with, but it is not a programming language. Its main mark is a description of the structure of the document content itself, because the machine itself is unable to resolve it. contents. The XML language is a subset of the SGML language, which retains the main function of SGML, and greatly reduces the complexity of SGML. It not only represents the contents of the document, but also represents the structure of the document, so that it can be understood by the machine while being understood by humans. Although HTML is an application of SGML, XML is a subset of SGML, but XML is never formed by adding certain elements to HTML, and there is a great difference between them. The biggest difference is that XML allows users to define their own elements for a particular purpose. In addition, the other one is the issue of XML's committed resolution, which is some of the special issues encountered when using HTML. XML requires a certain stringent standard, which is more stringent than the HTML browser's requirements for grammar and structures. The results of each analysis of the XML document are consistent, and HTML may make different analysis and display in different browsers. At the same time, the XML standard is a processing application for data, not just for web pages, which can also involve database e-commerce systems, as well as advanced applications of any display system. Developers can create custom data structures using XML according to specific industrial needs. These data structures and databases can be viewed on many devices without having to use custom interfaces to view the same data on different display devices. XML mainly has three elements: Document Type Declaration (DTD: Document Type Declaration) or XML Schema (XML Outline), Extensible Style Language (XLINK: EXTENSIBLE LINK LANGUAGE). DTD and XML Outline specify the logical structure of the XML file, define the elements in the XML file, the properties of the elements, and the relationship between the elements and element properties; Namespace implements unified XML document data representation and data mutual Integration; XSL is a language for specifying an XML document rendering style, which makes data independently of its performance, such as XSL enables a representation of the web browser to change documents, such as data display order, no need to communicate with the server. .

By changing the style sheet, the same document can be displayed larger or only the one layer is folded only, or the format that can be changed. XLINK will further extend the simple links of the current Web. Second, the Document Object Model (DOM) DOM is the abbreviation of Document Object Model, which is an application development, programming application interface (API) for web documentation. As a cross-platform for W3C, with language-independent interface specification, DOM provides standard program interfaces in different environments and applications, and can be implemented in any language. The DOM uses an object model and a range of interfaces to describe the contents and structures of the XML document, which uses objects to model documents. The basic functions of this object model implementation include: ● Describe the interface of document representation and operation; ● The behavior and attributes of the interface; ● The relationship between the interfaces and interoperability. DOM can parse structured XML documents, all content individuals in the document, elements, entities, properties, etc. are used to indicate the object model, and the entire document is seen as a structured information tree, not a simple text stream. The generated object model is the node of the tree, and the object contains the method and attributes. Therefore, all operations of the document are performed on the object tree. In the DOM, everything in the tree is an object, whether it is a root node or an entity attribute. There are three objects in the DOM: ● XML document object XML document is both an object, while also representing the entire XML document. It consists of root elements and child elements. ● The XML Node Object XML node object represents a node inside the XML document, such as elements, comments, namespaces, and more. ● The XML Node List XML Document Module list represents a collection of nodes. With DOM, developers can dynamically create XML documents, traverse structures, add, modify, delete content, and more. Its object-oriented features make people save a lot of effort when dealing with XML parses, is a powerful programming tool that meets the code reusability ideas. Third, MSXML is theoretically, according to the XML format definition, we can write an XML grammar analyzer, but in fact Microsoft has given us a XML syntax parser, that is, a dynamic link library called Msxml.dll In fact it is a COM (Component Object Model) object library, which encapsulates all objects needed when XML parsing. Because COM is an reusable object-independently in two-way format, you can call it in any language (such as VB, VC, Delphi, C Builder or even script language, etc.), in your application An Analysis of the XML Document. The main COM interfaces included in MSXml.dll are: 1. DomDocument DomDocument object is the foundation of XML DOM. You can use the properties and methods it exposed to browse, query, and modify the contents and structures of the XML document. DomDocument represents the top-level node of the tree, which implements all the basic methods of 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. ixmldomnode ixmldomnode is the basic objects, elements, properties, comments, process instructions, and 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 IxmlDomparseError IXMLDompivalError interface is used to return detailed information that appears during the parsed process, including error numbers, line numbers, character positions, and text descriptions. When using DomDocument's LOAD method to load an XML document, use ixmldomnode's SelectNodes (there are multiple queries to get a list of search results) or selectsingLenode (one of the results of the query, in the case of multiple cases Returns the first node found) Method for querying, create nodes and add nodes with Createnode and AppendChild methods, setting up and get the properties of the node with the IXMLDomelement's SetAttribute and GetAttribute methods. Fourth, the program implements how to use MSXML to parse the XML document in VC by a specific example. (1) The source XML document (XMLFile.xml) is as follows: 13 Protect We set "Device" in the source document, set its "name" property to "Test Device", add the "Model" node to it, and set its text as "3 ". (2) The source program is as follows: Coinitialize (null); // Initialization COM. CComptr spxmldom; hResult HR = SPXMLDOM.COCREATEINSTANCE (_UUIDOF (DomDocument)); // Create a parser instance. Variant_bool bsuccess = false; hr = SPXMLDOM-> LOAD (CCOMVARIANT (L "XMLFile.xml"), & bsuccess); // Load an XML document. CCOMBSTR BSTRSS (L "Device"); ccomptr spDevice; hr = spxmldom-> selectsinglenode (bstrss, & spDevice); // Search "Device". CCOMQIPTR spdev; spdev = spdevice; // set "Name" attribute of "Device".

转载请注明原文地址:https://www.9cbs.com/read-97191.html

New Post(0)