- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
发表于 2013-6-8 09:40:25
|
显示全部楼层
[code=csharp] StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
sb.Append("<root>");
sb.Append(" <Tips>success</Tips>");
sb.Append(" <Goods id=\"1000\">");
sb.Append(" <Title>清代历史</Title>");
sb.Append("");
sb.Append(" <Info>");
sb.Append(" <Value>1</Value>");
sb.Append(" <Gid>1</Gid>");
sb.Append(" </Info>");
sb.Append(" <Info>");
sb.Append(" <Value>2</Value>");
sb.Append(" <Gid>2</Gid>");
sb.Append(" </Info>");
sb.Append(" </Goods>");
sb.Append(" <Goods id=\"1001\">");
sb.Append(" <Title>汉代历史</Title>");
sb.Append("");
sb.Append(" <Info>");
sb.Append(" <Value>10</Value>");
sb.Append(" <Gid>3</Gid>");
sb.Append(" </Info>");
sb.Append(" </Goods>");
sb.Append("");
sb.Append("</root>");
XmlDocument doc = new XmlDocument();
doc.LoadXml(sb.ToString());
//Goods[@id='1000']/Info查询节点Goods下的所有Info条件是Goods的属性id=1000 @表示属性
foreach (XmlNode item in doc.SelectNodes("//Goods[@id='1000']/Info"))
{
//取Value
string value = item.SelectSingleNode("Value").InnerText;
//取Gid
string gid = item.SelectSingleNode("Gid").InnerText;
}[/code] |
|