在现有xml增加一个新的节点

 XmlDocument xml = new XmlDocument();

                    xml.Load(Server.MapPath("~/etao/IncrementIndex.xml"));

                

                    XmlNode item_ids = xml.GetElementsByTagName("item_ids")[0];

                    XmlElement newElement = xml.CreateElement("outer_id");

                    newElement.SetAttribute("action", "upload");

                    newElement.InnerText =pid;

                    item_ids.AppendChild(newElement);

                    XmlNodeList modified = xml.GetElementsByTagName("modified");

                    modified.Item(0).InnerText = DateTime.Now.ToString();

                    xml.Save(Server.MapPath("~/etao/IncrementIndex.xml"));


xml:
  
    
 <?xml version="1.0" encoding="utf-8" ?> 

- <root>

  <version>1.0</version> 

  <modified>2011-7-4 9:42:54</modified> 

  <seller_id>官网</seller_id> 

  <cat_url>etao/SellerCats.xml</cat_url> 

  <dir>etao/item/</dir> 

- <item_ids>

  <outer_id action="upload">ID1000018452</outer_id> 

 //新增加的

  <outer_id action="upload">ID1000018413</outer_id> 

 

  </item_ids>

  </root>


你可能感兴趣的:(xml)