Nodes for reading XML files in XML

Source: Internet
Author: User

1. Read the entire XML file, including child elements, text, and attributes.

CodeAs follows:

View code 1 Using System;
2 Using System. xml;
3
4 Namespace Readxmlfromfile
5 {
6 ///   <Summary>
7 /// Summary Description for class1.
8 ///   </Summary>
9 Class Class1
10 {
11 Static   Void Main ( String [] ARGs)
12 {
13 Xmltextreader Reader =   New Xmltextreader ( " Books. xml " );
14 While (Reader. Read ())
15 {
16 Switch (Reader. nodetype)
17 {
18 Case Xmlnodetype. element: // The node is an element.
19 Console. Write ( " < "   + Reader. Name );
20 Console. writeline ( " > " );
21 Break ;
22 Case Xmlnodetype. Text: // Display the text in each element.
23 Console. writeline (reader. value );
24 Break ;
25 Case Xmlnodetype. endelement: // Display the end of the element.
26 Console. Write ( " </ "   + Reader. Name );
27 Console. writeline ( " > " );
28 Break ;
29 }
30 }
31 Console. Readline ();
32 }
33 }
34 }

 

 

 

 

 

Reference: http://support.microsoft.com/kb/307548/zh-cn

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.