提未:缺少对像:root
set Doc = CreateObject( "Microsoft.XMLDOM ")
Doc.async = false
Doc.load(Server.MapPath( "data.xml "))
set root = Doc.DocumentElement
set book = Doc.createNode(1, "book ", " ")
set bookname = Doc.createNode(1, "name ", " ")
set publisher = Doc.createNode(1, "publisher ", " ")
set img = Doc.createNode(1, "img ", " ")
bookname.text = "Coldfusion "
publisher.text = "上海教育出版社 "
img.text = "img/5.jpg "
book.appendChild(bookname)
book.appendChild(publisher)
book.appendChild(img)
root.appendChild(book)
Doc.Save(Server.MapPath( "data.xml "))
call Doc.getElementsByTagName( "book ").item(Doc.DocumentElement.childNodes.length-1).setAttribute( "cost ", "200 ") '通过length来获取需要添加属性的节点所在的位置.
Doc.Save(Server.MapPath( "data.xml "))
------解决方案--------------------
可能data.xml有错误。
Set Doc = CreateObject( "Msxml2.DOMDocument ")
Doc.async = false
Doc.load Server.MapPath( "data.xml ")
If Doc.parseError.errorCode <> 0 Then
Response.Write Doc.parseError.reason
End If
------解决方案--------------------
同意楼上,我经常遇到类似问题,全部是Load时,xml不合规格解析错误造成的