Use the XML guide in Visual C # To read the XML sample code

Source: Internet
Author: User

// Configure //---------------------------------------------------------------------------------------------------

// The XmlReader class is used for reading Xml files. The following describes the class:

//

// Attributes (attribute ):

// ListBox: set this attribute to obtain the client control to display the content of the file read. (The ListBox control is used here)

// XmlPath: set this attribute to obtain the absolute path of a specified Xml file.

//

// Basilic Using (important reference ):

// System. Xml: This namespace encapsulates common classes for Xml operations. The XmlTextReader class is used in this class.

// XmlTextReader: This class provides the ability to read Xml files. It can verify whether the file format is good. If it is not a formatted Xml file, this class will throw an XmlException exception during reading. You can use

// Some methods are used to read, filter, and obtain the node name and value.

//

// Bool XmlTextReader. Read (): reads the next node in the stream. After reading the last node, call this method again. This method returns false.

// XmlNodeType XmlTextReader. NodeType: Type of the current node returned by this attribute

// XmlNodeType. Element Node

// XmlNodeType. EndElement End Element Node

// The first node of the XmlNodeType. XmlDeclaration document

// XmlNodeType. Text node

// Bool XmlTextReader. HasAttributes: whether the current node has any attribute. true or false is returned.

// String XmlTextReader. Name: returns the Name of the current node.

// String XmlTextReader. Value: returns the Value of the current node.

// String XmlTextReader. LocalName: returns the local name of the current node.

// String XmlTextReader. NamespaceURI: returns the namespace URI of the current node.

// String XmlTextReader. Prefix: returns the Prefix of the current node.

// Bool XmlTextReader. MoveToNextAttribute (): Move to the next attribute of the current node

// Configure //---------------------------------------------------------------------------------------------------

Namespace XMLReading

{

Using System;

Using System. Xml;

Using System. Windows. Forms;

Using System. ComponentModel;

/// <Summary>

/// Xml file Reader

/// </Summary>

Public class XmlReader: IDisposable

{

Private string _ xmlPath;

Private const string _ errMsg = "Error Occurred While Reading ";

Private ListBox _ listBox;

Private XmlTextReader xmlTxtRd;

# Region XmlReader Constructor

Public XmlReader ()

{

This. _ xmlPath = string. Empty;

This. _ listBox = null;

This. xmlTxtRd = null;

}

/// <Summary>

/// Constructor

/// </Summary>

/// <Param name = "_ xmlPath"> absolute path of the xml file </param>

  

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.