您的位置:首页 > Web前端 > Node.js

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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: