xml 添加 新项(asp.net)

来源:百度知道 编辑:UC知道 时间:2024/04/29 07:26:07
xml格式如下下:
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<item>
<title>美国海岸警卫队拟建北极基地</title>
<link>http://news.phoenixtv.com/world/usa/200710/1027_1394_274804.shtml</link>
<author>Goberl</author>
<guid>http://news.phoenixtv.com/world/usa/200710/1027_1394_274804.shtml</guid>
<pubDate>Sat, 27 Oct 2007 05:58:08 GMT</pubDate>
<comments>h</comments>
<description></description>
</item>
</channel>
</rss>
要求:
我想在此项中添加新项目(xml文档已经存在)

<?xml version=

public void WriteRss(string fpath, string title, string link, string author, string guid, DateTime pubDate, string comments, string description)
{
System.Xml.XmlDocument xdom = new System.Xml.XmlDocument();
try
{
xdom.Load(fpath);
}
catch (System.Exception)
{ }
if (xdom.OuterXml == "")
xdom.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><rss version=\"2.0\"><channel /></rss>");
System.Xml.XmlElement item = xdom.CreateElement("item");
System.Xml.XmlElement _title = xdom.CreateElement("title");
System.Xml.XmlElement _link = xdom.CreateElement("link");
System.Xml.XmlElement _author = xdom.CreateElement("author&qu