首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

求一段asp向xml中添加内容的代码?该如何解决

2012-02-21 
求一段asp向xml中添加内容的代码?xml中的内容是rootitem 111 /item/root要向里面增加的内容是ite

求一段asp向xml中添加内容的代码?
xml中的内容是
<root>
  <item> 111 </item>
</root>
要向里面增加的内容是
  <item> 222 </item>

[解决办法]
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load( "Test.xml ");
XmlNode root=xmlDoc.SelectSingleNode( "root ");
XmlElement xe1=xmlDoc.CreateElement( "item ");
XmlElement xesub1=xmlDoc.CreateElement( "item ");
xesub1.InnerText= "222 ";
xe1.AppendChild(xesub1);
root.AppendChild(xe1);
xmlDoc.Save( "Test.xml ");
[解决办法]
set xmlDoc=Server.CreateObject( "MSXML2.DOMDocument ")
x_file=server.MapPath( "Test.xml ")
xmlDoc.async=false
xmlDoc.load(x_file)
set root=xmlDoc.getElementsByTagName( "root ")(0)
set child=xmlDoc.CreateElement( "item ")
child.text= "222 "
root.AppendChild child
xmlDoc.save(x_file)

热点排行