Easily process XML data (1-1) in. NETFramework)

Source: Internet
Author: User
Tags object serialization
?? In. NETFramework, the XmlTextReader and XmlTextWriter classes provide read and write control over xml data. In this article, the author describes the system structure of the XML browser (Reader) and how they are combined with the XMLDOM and SAX specifiers. The author also demonstrated why ?? In the. NET Framework, the XmlTextReader and XmlTextWriter classes provide read and write control over xml data. In this article, the author describes the system structure of the XML browser (Reader) and how they are combined with the XMLDOM and SAX specifiers. The author also demonstrated how to use a browser to analyze and verify XML documents, how to create well-structured XML documents, and how to use functions to read/write large XML documents encoded based on Base64 and BinHex. Finally, the author explains how to implement a stream-based Read/Write Analyzer, which encapsulates all the readers in a separate class.

?? About three years ago, I attended a software research project titled "No XML, no programming future ". XML is indeed developing step by step. it has been embedded in. NET Framework. In this article, I will explain the roles and internal features of the APIs used to process XML documents in. NET Framework. then I will demonstrate some common functions.

?? XML from MSXML to. net

?? Before. NET Framework rendering, you are used to the application of MSXML service-a COM-based class library-to write windows XML drivers. Unlike classes in the. NET Framework, some code in the MSXML class library is deeper than the API, and is fully embedded at the underlying layer of the control system. MSXML can indeed communicate with your application, but it cannot really be combined with the external environment.

?? The MSXML class library can be imported in win32 and applied in CLR, but it can only be used as an external server component. However, the. NET Framework-based application can directly integrate the XML class with other namespaces of. NET Framework, and the written code is easy to browse.

?? As an independent component, MSXML analyzer provides some advanced features such as asynchronous analysis. This feature is in.. NET Framework and. other classes of the NET Framework are not provided, but the XML class in the NET Framework can be easily integrated with other classes to obtain the same effect, on this basis, you can add more functions.

??. The XML class in NET Framework provides the basic functions of analyzing, querying, and transforming XML data. In. NET Framework, you can find the classes that support Xpath query and XSLT conversion, and read/write XML documents. In addition ,. NET Framework also contains other XML processing classes, such as object serialization (XmlSerializer and the SoapFormatter class), using program configuration (AppSettingsReader class), and data storage (DataSet class ). In this article, I will only discuss classes that implement basic xml I/O control.

?? XML analysis mode

?? Since XML is a markup language, there should be a tool to analyze and understand the information stored in documents according to certain syntaxes. This tool is an XML analyzer-a component used to read markup text and return objects of the specified platform.

?? All XML analyzers, no matter which platform they belong to, are classified into the following two types: tree-based or event-based processors. These two types are usually implemented using XMLDOM (the Microsoft XML Document Object Model) and SAX (Simple API for XML. XMLDOM analyzer is a common tree-based API that uses XML documents as a memory structure tree. The SAX analyzer is an event-based API that processes every element in the XML data stream (it puts XML data into the stream for processing ). Generally, DOM can be loaded into and executed by a SAX stream. Therefore, these two types of processing are not mutually exclusive.

?? In general, the comparison between the SAX analyzer and the XMLDOM analyzer is quite different in their analysis modes. XMLDOM is well defined in its functionalition clustering. you cannot expand it. When it is processing a large file, it takes a lot of memory space to handle the huge clustering of functionalition.

?? The SAX analyzer uses the client to Process Analysis events through instances of objects on the existing specified platform. The SAX analyzer holds all the processing processes and pushes the data to the processing program. The processing program receives or rejects the processed data in sequence. This mode requires only a small amount of memory space.

??. NET Framework fully supports the XMLDOM mode, but it does not support the SAX mode. Why? Because. NET Framework supports two different analysis modes: XMLDOM analyzer and XML browser. It apparently does not support the SAX analyzer, but it does not mean it does not provide functions similar to the SAX analyzer. Using the XML browser, all the functions of the SAX can be easily implemented and more effective. Unlike the SAX analyzer, ALL. NET Framework browsers operate under the client exploitation program. In this way, the program itself can only "launch" the actually needed data and then jump out of the XML data stream. The SAX analysis mode needs to process all useful and useless information for the exploitation program.

?? A browser works based on the. NET Framework stream mode. it works in a way similar to a database cursor. Interestingly, classes that implement similar cursor analysis modes provide underlying support for XMLDOM analyzer in. NET Framework. The XmlReader and XmlWriter abstract classes are the basic classes of XML classes in all. NET frameworks, including the XMLDOM class, ADO. NET driver class, and configuration class. Therefore, in. NET Framework, you have two optional methods to process XML data. Use the XmlReader and XmlWriter classes to directly process XML data, or use the XMLDOM mode for processing. For more information about reading documents in. NET Framework, see the Cutting Edge topic article published in the August 2002 issue of MSDN.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.