Easy processing of XML data in the. NET Framework (1-1)

Source: Internet
Author: User
Tags xml parser
?? In the. NET framework, the XmlTextReader and XmlTextWriter classes provide read and write control over XML data. In this article, the authors describe the system architecture of XML browsers (reader) and how they are federated with the XMLDOM and sax specifiers. The authors also demonstrated how to use the browser to parse and validate XML documents, how to create well-formed XML documents, and how to use functions to read/write large XML documents based on BASE64 and BinHex encoding. Finally, the author describes how to implement a stream-based read/write parser that encapsulates the reader in a separate class.

?? About three years ago, I took part in a software research seminar with the theme "No XML, no programming Future". XML is indeed a step-by-step development, it has been embedded into. NET Framework. In this article, I will explain. NET Framework for working with the XML document's API and its internal characteristics, then I will demonstrate some common effects.

?? XML from MSXML to. Net

?? Before the. NET framework renders, you are accustomed to applying the MSXML service----a COM-based class library---the driver for writing Windows XML. Not like. NET Framework, some code in the MSXML class library is deeper than the API, and it is completely embedded in the bottom of the control system. MSXML does have the ability to communicate with your exploits, but it cannot really federate with the external environment.

?? The MSXML class library can be Win32 and applied in the CLR, but it can only be applied as an external server component. But the. NET Framework-based utility can be used directly with XML classes and other namespaces in the. NET Framework, and the code written is easy to navigate.

?? As a standalone component, the MSXML parser supplies some advanced features such as asynchronous parsing. This feature has no supply for the XML classes in the. NET Framework and for other classes in the. NET Framework, but the XML classes in the NET Framework can be easily combined with other classes to achieve the same effect, and on that basis you can add more power.

??. The XML classes in the NET framework provide the basis for analyzing, querying, and transforming the effectiveness of XML data. In the. NET framework, you can find classes that support XPath queries and XSLT transformations, and classes that read/write XML documents. In addition, the. NET Framework also contains other classes that handle XML, such as the serialization of objects (XmlSerializer and the SoapFormatter Class), using program configuration (Appsettingsreader Class), Data storage (DataSet Class). In this article, I'll only discuss classes that implement the underlying XML I/O control.

?? XML parsing pattern

?? Since XML is a markup language, there should be a tool that analyzes and understands the information stored in the document in a certain syntax. This tool is the XML parser---a component for reading markup text and returning objects of the specified platform.

?? All XML parsers, regardless of which control platform it belongs to, are divided into two categories: tree-based or event-based processors. These two classes are usually implemented using XMLDOM (the Microsoft XML Document Object Model) and sax (simple API for XML). The XMLDOM parser is an ordinary tree-based API---it emerges as a memory tree for XML documents. The SAX parser is an event-based API----IT processes each element in the XML data stream (it puts the XML data into the stream and then processes it). In general, Dom can be loaded and fulfilled by a sax stream, so the processing of these two classes is not mutually exclusion.

?? In general, the SAX parser is the opposite of the XMLDOM parser, and there are significant differences in their analysis patterns. XMLDOM is well defined in its functionalition gathering, you cannot enlarge it. When it is working on a large document, it takes up a lot of memory space to handle this grand gathering of functionalition.

?? The SAX parser uses the client to process the analysis events through an instance of an existing object on the specified platform. The SAX parser takes care of all the processing and "launches" the data into the handler, which in turn receives or rejects processing data. The advantage of this model is that it requires little memory space.

??. NET Framework fully supports XMLDOM mode, but it does not support sax mode. Why is it? Because the. NET framework supports two different profiling modes: The XMLDOM parser and the XML browser. It obviously does not support the SAX parser, but this does not mean that it does not provide the same effect as a SAX parser. All the functions of Sax through XML browser can be easily implemented and applied more effectively. Unlike the SAX parser, the. NET Framework's browsers all work under the client-side exploit program. In this way, the program itself can simply "eject" the data that is really needed and then jump out of the XML data stream. The Sax parsing pattern handles all the useful and useless information about using the program.

?? The browser works based on the. NET framework flow pattern, and it works like a database cursor. Interestingly, classes that implement a cursor-like analysis pattern provide the underlying support for the XMLDOM parser in the. NET framework. XmlReader, XmlWriter Two abstract classes are the underlying classes of XML classes in all. NET frameworks, including XMLDOM classes, ADO. NET driver classes and configuration classes. So in the. NET framework you have two options for working with XML data. Use the XmlReader and XmlWriter classes to process XML data directly, or in XMLDOM mode. More about reading documents in the. NET framework can be found in the MSDN August 2002 issue of the Cutting edge section article.


The above is the easy processing of XML data (1-1) in the. NET framework, and more about topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.