- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml;
- namespace XmlReader
- {
- class Program
- {
- static void Main(string[] args)
- {
- XmlDocument xmlDoc = new XmlDocument();
- xmlDoc.Load("data.xml");
- XmlElement xe = xmlDoc.DocumentElement;
- ReadElement(xe);
- }
- static void ReadElement(XmlElement xe)
- {
- if(xe.HasAttributes)
- {
- if (xe.Attributes[0] != null)
- {
- Console.WriteLine(xe.Attributes[0].Value);
- }
- }
- XmlNodeList list = xe.ChildNodes;
- foreach (XmlElement e in list)
- {
- ReadElement(e);
- }
- }
- }
- }
Traverse XmlElement
最新推荐文章于 2024-05-22 12:49:01 发布