您的位置:知识库 »

C#读写xml文件

作者: nileel  来源: CSDN  发布时间: 2008-09-09 19:13  阅读: 117492 次  推荐: 29   原文链接   [收藏]  
[1] C#读写xml文件
[2] C#读写xml文件
3、删除 <book genre="fantasy" ISBN="2-3631-4">节点的genre属性,删除 <book genre="update李赞红" ISBN="2-3631-4">节点。
Code
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");
最后结果为:
Code
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
<book>
</book>
</bookstore>
4、显示所有数据。
Code

[第1页][第2页]
29
6
标签:C# xml

热门文章

    最新文章

      最新新闻

        热门新闻