sitemap.xml的代码如下
<?xml version="1.0" encoding="UTF-8"?>
<urlset
      xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
            http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
  <url>
    <loc>http://www.abc.com/</loc>
    <priority>0.5</priority>
    <lastmod>2008-04-3T08:45:45+08:00</lastmod>
    <changefreq>always</changefreq>
  </url>
  <url>
    <loc>http://www.abc.com/aaa</loc>
    <priority>1.0</priority>
    <lastmod>2008-04-02T09:22+08:00</lastmod>
    <changefreq>always</changefreq>
  </url>
 <url>
    <loc>http://www.abc.com/bbb</loc>
    <priority>1.0</priority>
    <lastmod>2008-04-02T09:24+08:00</lastmod>
    <changefreq>always</changefreq>
  </url>
</urlset>我想在这个XML上自动添加节点。平时网上添加XML节点的那些代码都用不上,出错了。请各位大侠能给出能读写这段的代码!

解决方案 »

  1.   

    站点地图里面定义的节点,可以通过试用MapSource来寻找。。  自动添加节点的, 没有研究过。
    顶下楼主
      

  2.   

    因为文档含有命名空间,所以处理时不一样.写法有点麻烦.要使用namespacemanager来操作.
    先引用system.xml
    再引用system.xml.xpath具体的写法,你google搜一下.
      

  3.   

    它是XML文件,以XML文件的方式读写不就行了
      

  4.   

    好像搜啊.要不然也不会在这里求救了,普通的XML方式读写是写不了的.好像一定要命名空间去搞,找不到一个示例!
      

  5.   

    呵呵,我也遇到这样的问题,的确用普通的Xpath不可以查询读写。
    等等我去把我以前的源码找一下给你看
      

  6.   

    /// <summary>
        /// 增加一级目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            string sitemap = Server.MapPath("../Web.sitemap");        XmlDataDocument doc = new XmlDataDocument();
            doc.Load(sitemap);
            XmlNode root = doc.GetElementsByTagName("siteMapNode").Item(0);        SiteMapSection df = new SiteMapSection();
            df.LockItem = false;        XmlElement el = doc.CreateElement("siteMapNode");
            el.SetAttribute("title", TextBox1.Text);
            el.SetAttribute("roles", "");
            el.SetAttribute("xmlns", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
            root.AppendChild(el);
            el.InnerText = "";
            doc.Save(sitemap);}恩 我做的是只有两级的目录树,这个是向sitemap中添加一级的
      

  7.   

    string sitemap = Server.MapPath("../Web.sitemap");            XmlDataDocument doc = new XmlDataDocument();
                doc.Load(sitemap);            SiteMapSection df = new SiteMapSection();
                df.LockItem = false;
                XmlNodeList nodeList = doc.GetElementsByTagName("siteMapNode");            XmlNode xn = doc.SelectSingleNode("//*[local-name()='siteMapNode' and  @title='" + DropDownList1.SelectedItem.Text + "']");
                XmlElement er = doc.CreateElement("siteMapNode");
                er.SetAttribute("title", TextBox2.Text);
                er.SetAttribute("url", TextBox3.Text);
                er.SetAttribute("roles", "");
                er.SetAttribute("xmlns", "http://schemas.microsoft.com/AspNet/SiteMap-File-1.0");
                xn.AppendChild(er);            doc.Save(sitemap);
    这个是二级的哦,你用的是1.1啊
    我读写的是web.sitemap文件
      

  8.   

    厄,应该是吧,我一开始接触的就是2.0。你试试看把那个xmlns换一下,看看