我想插入的记录如下:
<siteMapNode LinkUrl="a.aspx" Title="a" />
也就是插入后的效果为:
<siteMap>
<siteMapNode LinkUrl="a.aspx" Title="a" />
<siteMapNode LinkUrl="b.aspx" Title="b" />
<siteMapNode LinkUrl="c.aspx" Title="c" />
</siteMap>
网上介绍的插入数据的方法都是插入这种格式的:
<siteMapNode>
  <LinkUrl>a.aspx</LinkUrl>
   <Title>a</Title>
</siteMapNode>

解决方案 »

  1.   

    有什么难的嘛??
    插入siteMapNode 结点,然后设置属性就行了
      

  2.   

    给段代码看看。哈哈。插入节点就变成这样了:
    <siteMapNode>
    </siteMapNode>
      

  3.   

    XmlElement xel = xmlDoc.CreateElement("siteMapNode");//创建一个<siteMapNode>节点
    xel.SetAttribute("LinkUrl","a.aspx");//设置该节点LinkUrl属性
    xel.SetAttribute("Title","a");//设置该节点Title属性
      

  4.   

    public void Insert()
    {
    string xmlPath = System.Web.HttpContext.Current.Server.MapPath("bookstore.xml");
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(xmlPath);
    XmlNode root = xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>
    XmlElement xel = xmlDoc.CreateElement("book");//创建一个<book>节点
    xel.SetAttribute("genre","李赞红");//设置该节点genre属性
    xel.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性 XmlElement xesub1 = xmlDoc.CreateElement("title");
    xesub1.InnerText="CS从入门到精通";//设置文本节点
    xel.AppendChild(xesub1);//添加到<book>节点中
    XmlElement xesub2=xmlDoc.CreateElement("author");
    xesub2.InnerText="候捷";
    xel.AppendChild(xesub2);
    XmlElement xesub3=xmlDoc.CreateElement("price");
    xesub3.InnerText="58.3";
    xel.AppendChild(xesub3); root.AppendChild(xel);//添加到<bookstore>节点中
    xmlDoc.Save(xmlPath);
    }
    //bookstore.xml
    <?xml version="1.0" encoding="utf-8"?>
    <bookstore>
      <book ISBN="2-3631-4">
        <title>Oberon's Legacy</title>
        <author>Corets, Eva</author>
        <price>5.95</price>
      </book>
      <book genre="update李赞红" ISBN="2-3631-4">
        <title>CS从入门到精通</title>
        <author>亚胜</author>
        <price>58.3</price>
      </book>
      <book genre="update李赞红" ISBN="2-3631-4">
        <title>CS从入门到精通</title>
        <author>亚胜</author>
        <price>58.3</price>
      </book>
    </bookstore>
      

  5.   

    晕,我不要这种格式:
    <siteMapNode>
    </siteMapNode>
    我要的是:
    <siteMapNode />
    这种格式。
      

  6.   

    string xmlPath = System.Web.HttpContext.Current.Server.MapPath("bookstore.xml");
    XmlDocument xmlDoc = new XmlDocument();
    xmlDoc.Load(xmlPath);
    XmlNode root = xmlDoc.SelectSingleNode("bookstore");//查找<bookstore>
    XmlElement xel = xmlDoc.CreateElement("book");//创建一个<book>节点
    xel.SetAttribute("genre","李赞红");//设置该节点genre属性
    xel.SetAttribute("ISBN","2-3631-4");//设置该节点ISBN属性root.AppendChild(xel);//添加到<bookstore>节点中
    xmlDoc.Save(xmlPath);这个不行吗?
    你都没有试试