. Net framework processing xml

Source: Internet
Author: User
Tags object serialization xml reader

Before the emergence of. NET Framework, I used to use the 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 it is completely embedded at the underlying layer of the operating 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 used in CLR, but it can only be used as an external server component. However, Applications Based on. NET Framework can directly use XML classes and Other Namespaces of. NET Framework, and the written code is easy to read.

As an independent component, MSXML analyzer provides some advanced features such as Asynchronous analysis. This feature is available in.. NET Framework and. other classes of the. NET Framework are not provided ,. the integration of XML classes in the. NET Framework and other classes can easily obtain the same functions. On this basis, you can add more functions.

The XML class in. NET Framework provides basic functions for analyzing, querying, and transforming XML data. In. NET Framework, you can find 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), application configuration (AppSettingsReader class), and data storage (DataSet class ).

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

The main function of analyzer is to check whether the XML file has a structure error, strip the tag in the XML file, read the correct content, and hand it to the next application for processing. XML is a markup language for structured file information. The XML specification provides a detailed rule for how to mark the structure of a file, the parser is the software written according to these rules (written in Java ). Like HTML, the browser must have an HTML analyzer so that the browser can "read" various webpages consisting of HTML tags and display them in front of us. If the HTML Parser of the browser does not understand the mark, the error message will be returned to us.

All XML analyzers, no matter which operating platform they belong to, are classified into 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 treats XML documents as a memory structure tree. The SAX analyzer is an event-based API that processes each element in the XML data stream (it puts XML data into the stream for processing ). Generally, DOM can be loaded 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 set. You cannot extend it. When processing a large file, it takes a lot of memory space to process the huge set of functionalition.

The SAX analyzer uses client applications to Process Analysis events through instances of objects on the existing specified platform. The SAX analyzer controls the entire processing process and "releases" the data to the processing program, which accepts or rejects the data in turn. 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. Because. NET Framework supports two different analysis modes: XMLDOM analyzer and XML reader. It obviously does not support the SAX analyzer, but it does not mean it does not provide performance similar to the SAX analyzer. All the functions of the XML reader SAX can be easily implemented and used more effectively. Unlike the SAX analyzer, the. NET Framework reader operates under the client application. In this way, the application itself can only "launch" The actually needed data and then jump out of the XML data stream. The SAX analysis mode must process all useful and useless information for applications.

A reader works based on the. NET Framework stream mode, which is similar to a database cursor. Interestingly, classes similar to the cursor Analysis Mode 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.

XML Reader supports a programming interface used to connect XML documents and "launch" the data you want. If you have a deeper understanding of the reader, you will find that the reader works in a way similar to how our desktop applications extract data from the database. Database Service returns a cursor object that contains all query result sets and returns a reference to the start address of the target dataset. The XML reader client receives a reference pointing to the reader instance. This instance extracts the underlying data streams and presents the retrieved data as an XML tree. The reader class provides read-only and forward cursors. You can use the method provided by the reader class to scroll the cursor to traverse each piece of data in the result set. From the reader, the XML document is not a label text file, but a serialized node set. It is a special cursor mode in. NET Framework. In. NET Framework, you cannot find any other similar API function.

The reader and XMLDOM analyzer are different. An XML reader is read-only and has no concept of parent, child, ancestor, or sibling node. In. NET Framework, reading and writing XML documents is divided into two completely different functions, which are completed by the XmlReader and XmlWriter classes respectively. To edit an XML document, you can use the XMLDOM analyzer.

. Net framework processes the main xml package in the System. Xml namespace, while xml Serialization is in the System. Xml. Serialization namespace. Finally, let's briefly talk about the concept of DTD.

Document Type Definition (DTD) is a standard that enables seamless data exchange between commercial organizations. For example, if two companies A and B in the same industry exchange data with each other using XML files, Company A uses the price mark to indicate the price information of their products, company B may use the price to indicate the price information. If an XML application reads the information in their respective XML files, if it only knows the price information indicated in the price tag, if the price information of Company B cannot be obtained, errors will occur. Obviously, for entities that want to use XML files to exchange information, there must be a convention between them-the tags that can be used to write XML files and the child elements that can be included in the parent element, the order in which each element appears, and how the attributes in the element are defined. This person can help us easily compile an application based on this DTD and automatically capture what we are interested in online. This is the so-called DTD. Company A and Company B must follow A standard when exchanging data.

Currently, several defined DTD types are available, such as MathML and SMIL. Mathematical Markup Language (MathML) is an XML-based standard used to write Mathematical symbols and formulas on the Internet. It was proposed by W3C mathematical workgroup. Because the structure of mathematical symbols and formulas is complex and there are multiple logical relationships between symbols, the format of MathML is very cumbersome. This is too complicated for the East and East. I am too lazy to study it. SMIL, like smile, is used to manipulate multimedia clips (organic and intelligent combinations of multimedia clips ). It seems this is really good! The SMIL language is a set of well-defined and very simple labels. It is used to specify multimedia clips (Multimedia includes audio files, video files, animations, images, and texts) when, where, and in what way. These are rarely used at ordinary times and do not know much about these things! I have time to watch it. (I'm so overwhelmed by work! Really tiring !).

The article is written here. Let's get to the end!

Henry

 

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.