关于xml 多出xmlns="" XmlNode root = xmlDoc.SelectSingleNode("news");参考http://www.cnblogs.com/ziyan22/archive/2007/08/23/866456.html 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 搂主上贴中我就猜到搂主是想创建XML,而不是读取,所以说根本不用调用load了搂主完全改成下面的,就行了:string url = Server.MapPath("/sitemap/Sitemaps.xml");XmlDocument xmlDoc = new XmlDocument();string news_title = "12311";string news_time = "2008-12-05";XmlNode root = xmlDoc.CreateElement("histNews");XmlElement news = xmlDoc.CreateElement("news");XmlElement title = xmlDoc.CreateElement("title");title.InnerText = news_title;news.AppendChild(title);XmlElement time = xmlDoc.CreateElement("time");time.InnerText = news_time;news.AppendChild(time);root.AppendChild(news);xmlDoc.AppendChild(root);xmlDoc.Save(url); 噢,没标出我改动的地方,标示一下吧:string url = Server.MapPath("/sitemap/Sitemaps.xml"); XmlDocument xmlDoc = new XmlDocument(); //xmlDoc.Load(url); string news_title = "12311"; string news_time = "2008-12-05"; XmlNode root = xmlDoc.CreateElement("histNews"); XmlElement news = xmlDoc.CreateElement("news"); XmlElement title = xmlDoc.CreateElement("title"); title.InnerText = news_title; news.AppendChild(title); XmlElement time = xmlDoc.CreateElement("time"); time.InnerText = news_time; news.AppendChild(time); root.AppendChild(news); xmlDoc.AppendChild(root); xmlDoc.Save(url); 注意:搂主还需确信sitemap文件夹是存在的,否则得先创建好 另外,上面代码还删掉了一句:XmlNode root = xmlDoc.DocumentElement; 刚才测试了一下上面代码是对的 XML文件: <histNews xmlns="http://www.163.com/rss/0.9"> <news> <title>什么什么什么 </title> <time>2008-12-11 </time> </news> <histNews> 结尾的时候要关闭</histNews> 楼主还在问这个问题啊,注意加一个参数。还有你的<histNews>... </histNews> 结束标记xmlDoc.CreateElement("news", "http://www.163.com/rss/0.9"); string url = Server.MapPath("/sitemap/Sitemaps.xml"); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(url); string news_title = "12311"; string news_time = "2008-12-05"; XmlNode root = xmlDoc.DocumentElement; XmlElement news = xmlDoc.CreateElement("news", "http://www.163.com/rss/0.9"); XmlElement title = xmlDoc.CreateElement("title", "http://www.163.com/rss/0.9"); title.InnerText = news_title; news.AppendChild(title); XmlElement time = xmlDoc.CreateElement("time", "http://www.163.com/rss/0.9"); time.InnerText = news_time; news.AppendChild(time); root.AppendChild(news); xmlDoc.Save(url); 纠正一下,呵呵,搂主帖子已经说明了:要去掉XML名称空间的声明搂主是要创建这个XML,所以不需要这个XML文件事先已经存在的,直接使用3楼代码就可以啦 C#的窗口应用程序中,新建的一个类如何调用原窗体的控件? 生活中常用的桌面软件有多少是C#开发的? remoting技术相关 c# 如何获取从1970-1-1到目前为止的毫秒数 C# 发送接收文件 怎么改项目名? 在vs2005中怎么控制层 求quoted-printable解码代码片断 整个WinForm逐渐变成灰色!!! 居然有如此Bug!!!!!!!!!! 哥们,谁有做过CODE128A条形码的请通知本姑娘一下,想向你老人家讨教一下! 在C#验证码里有随机大小写、奇偶数怎么写。
string url = Server.MapPath("/sitemap/Sitemaps.xml");
XmlDocument xmlDoc = new XmlDocument();
string news_title = "12311";
string news_time = "2008-12-05";
XmlNode root = xmlDoc.CreateElement("histNews");
XmlElement news = xmlDoc.CreateElement("news");
XmlElement title = xmlDoc.CreateElement("title");
title.InnerText = news_title;
news.AppendChild(title);
XmlElement time = xmlDoc.CreateElement("time");
time.InnerText = news_time;
news.AppendChild(time);
root.AppendChild(news);
xmlDoc.AppendChild(root);
xmlDoc.Save(url);
XmlDocument xmlDoc = new XmlDocument();
//xmlDoc.Load(url);
string news_title = "12311";
string news_time = "2008-12-05";
XmlNode root = xmlDoc.CreateElement("histNews");
XmlElement news = xmlDoc.CreateElement("news");
XmlElement title = xmlDoc.CreateElement("title");
title.InnerText = news_title;
news.AppendChild(title);
XmlElement time = xmlDoc.CreateElement("time");
time.InnerText = news_time;
news.AppendChild(time);
root.AppendChild(news);
xmlDoc.AppendChild(root);
xmlDoc.Save(url); 注意:搂主还需确信sitemap文件夹是存在的,否则得先创建好
<news>
<title>什么什么什么 </title>
<time>2008-12-11 </time>
</news>
<histNews>
结尾的时候要关闭</histNews>
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(url);
string news_title = "12311";
string news_time = "2008-12-05";
XmlNode root = xmlDoc.DocumentElement;
XmlElement news = xmlDoc.CreateElement("news", "http://www.163.com/rss/0.9");
XmlElement title = xmlDoc.CreateElement("title", "http://www.163.com/rss/0.9");
title.InnerText = news_title;
news.AppendChild(title);
XmlElement time = xmlDoc.CreateElement("time", "http://www.163.com/rss/0.9");
time.InnerText = news_time;
news.AppendChild(time);
root.AppendChild(news);
xmlDoc.Save(url);
搂主是要创建这个XML,所以不需要这个XML文件事先已经存在的,直接使用3楼代码就可以啦