C# 中对于Xmlnode节点怎么获得当前节点的标签名?
2个回答
展开全部
using System;
using System.IO;
using System.Xml;
publicclass Sample {
publicstaticvoid Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"<price>19.95</price>" +
"</book>");
XmlNode root = doc.FirstChild;
//Display the contents of the child nodes.
if (root.HasChildNodes)
{
for (int i=0; i<root.ChildNodes.Count; i++)
{
Console.WriteLine(root.ChildNodes[i].Name);
}
}
}
}
using System.IO;
using System.Xml;
publicclass Sample {
publicstaticvoid Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<book ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"<price>19.95</price>" +
"</book>");
XmlNode root = doc.FirstChild;
//Display the contents of the child nodes.
if (root.HasChildNodes)
{
for (int i=0; i<root.ChildNodes.Count; i++)
{
Console.WriteLine(root.ChildNodes[i].Name);
}
}
}
}
参考资料: http://msdn.microsoft.com/zh-cn/library/system.xml.xmlnode.childnodes(v=vs.80).aspx
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询