asp添加xml节点问题
我用asp添加xml节点成功了 语句是这样的
这是链接的
set xmldoc=server.CreateObject( "microsoft.xmldom ") '链接xml
xmldoc.load(server.mappath( "data.xml "))
这是添加的
xmlDoc.selectSingleNode( "records/record ").appendchild(xmlDoc.createelement( "item ") )
这是添加的属性
xmlDoc.selectSingleNode( "records/record/item ").setAttribute "item_url ", "images/toto.jpg "
xmlDoc.selectSingleNode( "records/record/item ").setAttribute "link ", "www.photocnc.com "
xmlDoc.selectSingleNode( "records/record/item ").setAttribute "itemtitle ", "图客 "
我的xml结构是这样的:
<?xml version= "1.0 " encoding= "utf-8 "?>
<records>
<record>
<name> 王涛 </name>
<qq> qq号码 </qq>
<email> 邮箱 </email>
<wangtao title= "标题 " body= "内容 "/>
<item item_url= "asfd " link= "asdf " itemtitle= "asdf "/>
</record>
</records>
我想变成这样
<?xml version= "1.0 " encoding= "utf-8 "?>
<records>
<record>
<name> 王涛 </name>
<qq> qq号码 </qq>
<email> 邮箱 </email>
<wangtao title= "标题 " body= "内容 "/>
<item item_url= "asfd " link= "asdf " itemtitle= "asdf "/>
<item item_url= "images/index.jpg " link= "www.baidu.com " itemtitle= "baidu "/>
</record>
</records>
添加一个是成功了 但是我还想添加一个一样的节点 属性的名字也是一样的 就是属性值不一样 我有尝试这样添加 但是却变成了修改 然后后面加多了一个节点item 但是是没有属性的
请教各位大虾 有没有什么方法能在添加一个 <item item_url= "images/index.jpg " link= "www.baidu.com " itemtitle= "baidu "/> 这个节点
[解决办法]
Set oNode = xmlDoc.createelement( "item ")
oNode.setAttribute "item_url ", "images/toto.jpg "
oNode.setAttribute "link ", "www.photocnc.com "
oNode.setAttribute "itemtitle ", "图客 "
Set oRecord = xmlDoc.selectSingleNode( "records/record ")
oRecord.appendChild(oNode)
xmlDoc.save "xxx.xml "
Set oNode = Nothing
Set oRecord = Nothing