c读取XML中的属性值
//使用XmlTextReader
//效率比DOM高
XmlTextReader reader = new XmlTextReader(Server.MapPath("xml.xml"));
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "name") //如果是
{
while (reader.MoveToNextAttribute())
{
if (reader.Name == "ID") //ID属性
{
Response.Write(string.Format("ID: {0}", reader.Value));
}
if (reader.Name == "TEXT") //TEXT属性
{
Response.Write(string.Format("Text: {0}", reader.Value));
}
}
Response.Write("
");
}
}
}
/*********************************/
System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); 下一篇:搜索引擎对网站作弊的判断 上一篇:网站建设中有用的代码
doc.Load(Server.MapPath("xml.xml"));
foreach (XmlNode tmpNode in doc.SelectSingleNode("GN").ChildNodes)
{
tmpNode.Attributes["id"].Value;
tmpNode.Attributes["