节点。XmlNodeList xnl=xmlDoc.SelectSingleNode(\"bookstore\").ChildNodes; foreach(XmlNode xn in xnl) { XmlElement xe=(XmlElement)xn;
if(xe.GetAttribute(\"genre\")==\"fantasy\") {
xe.RemoveAttribute(\"genre\");//删除genre属性 }
else if(xe.GetAttribute(\"genre\")==\"update李赞红\") {
xe.RemoveAll();//删除该节点的全部内容
} }
xmlDoc.Save(\"bookstore.xml\");
//====================
最后结果为:
Oberon's Legacy Corets, Eva 5.95
4、显示所有数据。
XmlNode xn=xmlDoc.SelectSingleNode(\"bookstore\"); XmlNodeList xnl=xn.ChildNodes; foreach(XmlNode xnf in xnl) { XmlElement xe=(XmlElement)xnf; Console.WriteLine(xe.GetAttribute(\"genre\"));//显示属性值 Console.WriteLine(xe.GetAttribute(\"ISBN\")); XmlNodeList xnf1=xe.ChildNodes; foreach(XmlNode xn2 in xnf1) { Console.WriteLine(xn2.InnerText);//显示子节点点文本 } }
转载自:http://blog.csdn.net/s98/archive/2004/10/17/140307.aspx
XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load(\"c:/aaa.xml\");
XmlNode xn=xmlDoc.SelectSingleNode(\"todate\"); XmlNodeList xnl=xn.ChildNodes; foreach(XmlNode xnf in xnl) {
XmlElement xe=(XmlElement)xnf;
XmlNodeList xnf1=xe.ChildNodes;
Response.Write(xnf1[0].InnerText);//显示子节点点文本 }
XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load(\"c:/aaa.xml\");
XmlNode xn=xmlDoc.SelectSingleNode(\"todate\"); XmlNodeList xnl=xn.ChildNodes; foreach(XmlNode xnf in xnl) {
XmlElement xe=(XmlElement)xnf;
XmlNodeList xnf1=xe.ChildNodes;
xnf1[0].InnerText=\"10\"; xmlDoc.Save(\"c:/aaa.xml\");