C# XML - XmlNode and XmlAttribute
2014-07-02 14:31
471 查看
public static string TestXML(string path) { XmlDocument doc = new XmlDocument(); doc.Load(path); XmlNode root = doc.FirstChild; ParseXmlNode(root); XmlNode nextNode = root.NextSibling; while (nextNode != null) { ParseXmlNode(nextNode); nextNode = nextNode.NextSibling; } return ""; } public static void ParseXmlNode(XmlNode root) { if (root == null) { return; } bool hasChild = root.HasChildNodes; if (hasChild) { for (int i = 0; i < root.ChildNodes.Count; i++) { XmlNode childnode = root.ChildNodes[i]; XmlAttributeCollection attrlist = childnode.Attributes; XmlAttribute kifattr = null; string childNodeName = childnode.Name; if (attrlist != null) { kifattr = attrlist["KifSchema"]; } if (kifattr != null) { Console.WriteLine(childNodeName + "\t" + kifattr); } ParseXmlNode(childnode); } } else { Console.WriteLine("name is: " + root.Name + " value is: " + root.InnerText); //Console.WriteLine(); } }
相关文章推荐
- PHP - Retrieving Node and Attribute Values From XML
- Xml/Binary SerializerHelper and XmlReader read xml node/attribute on foward-only sequential
- PHP - XML - Modifying Node and Attribute Values
- C# testJsonAsXMLNodeAttribute - XML& json & Collections - XmlNode, XmlElement, XmlAttribute,Dictionary,List
- Difference between node and element in xml
- C#操作XML- SelectSingleNode总是返回NULL
- Select XML Nodes by Attribute Value [C#]
- C# and XML Source Code Documentation(转载自CodeProject)
- Open XML C# and Word docx documents
- Why Java Sucks and C# Rocks(3):Attribute与Annotation
- C#操作xml SelectNodes,SelectSingleNode总是返回NULL原因和解决方案
- Serialize and deserialize objects as Xml using generic types in C# 2.0
- C# read xml from a string and performance test
- Why Java Sucks and C# Rocks(3):Attribute与Annotation
- Convert XElement to XmlNode (and Convert XmlNode to XElement){转载}
- xml中的元素(element)和节点(node)——C#
- 在C#中操作XML,Node节点操作。
- C# Read and Modify XML File
- 20100603 学习记录:常用类型--XMLDocument XMLNode XMLElement XMLAttribute XMLFragment XML
- c# 操作Xml中SelectSingleNode方法中的xpath用法