Figure 6 of the DOTNET framework: system. xml

Source: Internet
Author: User
Tags dotnet xml reader

(Disclaimer: this series is intended for you only. the Net Framework is not an explanation of syntax and class usage. Therefore, you can only briefly describe the mentioned classes. If you have any questions, go to msdn to check)

 

In the previous article, we made a preliminary study on system. reflection. We will explain the winform application at the beginning of this article.ProgramThe process framework, but I suddenly thought there was something about XML, so I had to make up this article. Let's talk about the application later. Sorry for the mistake!

 

XML is a markup language, and a tool should be used to analyze and understand information stored in documents 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 Net Framework supports two different analysis modes: xmldom analyzer and XML reader. Let's look at the figure

 

 

 

 

1. Reader:

It works like a database cursor. 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.
Xmlreader is an abstract base class that provides non-Cache and read-only access to XML document data. Two child classes inherit and extend them.

Xmltextreader: A reader that inherits from xmlreader and provides fast, non-cached, and only accessible XML document data.

Xmlnodereader: inherits from xmlreader and provides a fast, non-cached, only-in-access reader for XML data in the XML file node.

Xmlwrite: A writer abstract base class. The writer provides a fast, non-cache, and only-in method to generate streams or files containing XML data.

2. Dom Analyzer:

Xmlnode: A single node in the XML document. Is the base class in Dom implementation.

Xmlattribute: inherited from xmlnode, indicating the attributes of nodes in the XML document.

Xmldocument: inherited from xmlnode, indicating the XML document.

Xmlbeannode: gets the node that is close to the node (before or after.

 

XML is also a data storage format, which is like a database table. Then he used the data source architecture model we mentioned in system. Data. Let's recall the three data-layer architecture models.

 

1. Table data entry: A table instance processes all rows in the database table. (The adapter carries a table, which represents the database and allows you to fill in, delete, modify, and query data)

2. row data entry: access a single record object in the table, one row per instance. (datareader, the row data here can only be read, but cannot be modified. each reader. next (), a data row is returned .)

3. Data Er (ORM):. Net does not have this mode, and the orm itself is very complicated. I will not explain it here.

 

The reader here is equivalent to the datareader in system. data. It reads data one by one, and each data entry is an instance in reader, so it belongs to the row data entry. Analyzer is like an adapter. It loads all the data in an XML document at a time. A Dom is an instance of a table (document), so it is a row data entry.

 

Let's take a look at how to operate XML in. net.

 

Reader

 

Xmltextreader axmltextreader =   New Xmltextreader ( @" C: \ Text. xml " );
While (Axmltextreader. Read ())
{
//
}
Axmltextreader. Close ();


Xmltextwriter xmlwriter =   New Xmltextwriter (URL, system. Text. encoding. utf8 );
Xmlwriter. writestartdocument ();
Xmlwriter. writestartelement ( " Root " );
Xmlwriter. writestartelement ( " Leaf " );
Xmlwriter. writestring ( " Test " );
Xmlwriter. writeendelement ();
Xmlwriter. writeendelement ();
Xmlwriter. Close ();
 

 

Analyzer:

 

 

Xmldocument xmldoc =   New Xmldocument ();
// Create Root Node
Xmlelement Root = Xmldoc. createelement ( " Root " );
Xmldoc. appendchild (Root );
Xmlnode book = Xmldoc. createelement ( " Book " );
Xmlelement title = Xmldoc. createelement ( " Title " );
Title. innertext =   " SQL Server " ;
Book. appendchild (title );
Xmlelement ISBN = Xmldoc. createelement ( " ISBN " );
ISBN. innertext =   " 444444 " ;
Book. appendchild (ISBN );
Xmlelement author = Xmldoc. createelement ( " Author " );
Author. innertext =   " Jia " ;
Book. appendchild (author );
Xmlelement price = Xmldoc. createelement ( " Price " );
Price. innertext =   " 120 " ;
Price. setattribute ( " Unit " , "" );
Book. appendchild (price );
Root. appendchild (book );
Xmldoc. Save ( " Books. xml " );

 

 

OK. Here we will introduce the XML operations.

 

Next article: Figure 7 of the DOTNET framework: winform

 

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.