- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
发表于 2013-7-2 14:39:13
|
显示全部楼层
[code=csharp]StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sb.Append("<tags>");
sb.Append(" <group name=\"测试组\">");
sb.Append(" <tag name=\"测试标签1\">");
sb.Append(" <value>标签1</value>");
sb.Append(" <tips>标签说明1</tips>");
sb.Append(" </tag>");
sb.Append(" <tag name=\"测试标签2\">");
sb.Append(" <value>标签2</value>");
sb.Append(" <tips>标签说明2</tips>");
sb.Append(" </tag>");
sb.Append(" </group>");
sb.Append(" <group name=\"测试组1\">");
sb.Append(" <tag name=\"测试标签3\">");
sb.Append(" <value>标签3</value>");
sb.Append(" <tips>标签说明3</tips>");
sb.Append(" </tag>");
sb.Append(" <tag name=\"测试标签4\">");
sb.Append(" <value>标签4</value>");
sb.Append(" <tips>标签说明4</tips>");
sb.Append(" </tag>");
sb.Append(" </group> ");
sb.Append("</tags>");
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(sb.ToString());
string group = string.Empty, tag = string.Empty;
foreach (XmlNode node in xmlDoc.SelectNodes("//group"))
{
richTextBox1.AppendText(node.Attributes["name"].Value + "\r\n");
foreach (XmlNode item in node.SelectNodes("tag"))
{
tag = item.Attributes["name"].Value + "\r\n";
string value = item.SelectSingleNode("value").InnerText;
richTextBox1.AppendText(" " + value);
string tips = item.SelectSingleNode("tips").InnerText;
richTextBox1.AppendText(" " + tips);
richTextBox1.AppendText(" " + tag);
}
}[/code]
|
|