1、写入文件前的XML文档(Feeds.xml)
<?xml version="1.0" encoding="utf-8" ?> <Feeds> <Feed> <Name>ScottGu Blog</Name> <Url>http://weblogs.asp.net/scottgu/rss.aspx</Url> </Feed> <Feed> <Name>Weblogs.ASP.NET Main Feed</Name> <Url>http://weblogs.asp.net/MainFeed.aspx</Url> </Feed> </Feeds>
2、C#文件
XElement feedml = XElement.Load(Server.MapPath("Feeds.xml"));
feedml.Add(new XElement("Feed",
new XElement("Name","wangli"),
new XElement("Url","http://hi.csdn.net/linuux/") ));
feedml.Save(Server.MapPath("Feeds.xml"));
3、运行上面的程序后的XML文档
<?xml version="1.0" encoding="utf-8" ?> <Feeds> <Feed> <Name>ScottGu Blog</Name> <Url>http://weblogs.asp.net/scottgu/rss.aspx</Url> </Feed> <Feed> <Name>Weblogs.ASP.NET Main Feed</Name> <Url>http://weblogs.asp.net/MainFeed.aspx</Url> </Feed> <Feed> <Name>wangli</Name> <Url>http://hi.csdn.net/linuux/</Url> </Feed> </Feeds>