ASP3 / XMLDOM / updating nodes -- HELP PLEASE
Hello everyone!
I got a problem here (I use ASP (3.0) with Microsoft.XMLDOM). The thing is I have an XML tree with some information. And I need to modify data stored in it. It's a simple 2-level structure. Just provide me a working example of how to modify the data in some node/attribute of this node and then to save the complete modified XML structure back to the Session variable.
I tried to do it the following way but it seems it's not working..
sub init()
set xmlOrder = Server.CreateObject("Microsoft.XMLDOM")
set xmlOrderItem = xmlOrder.createElement("xml_order")
xmlOrderItem.setAttribute "id","1"
xmlOrderItem.setAttribute "name","my order"
xmlOrder.appendChild(xmlOrderItem)
set Session("XML_ORDER") = xmlOrder
set xmlOrderItem = nothing
set xmlOrder = nothing
end sub
... i also have the procedure which adds the second level (xml_orderline) to the initialized tree:
<xml_order id="1" name="my order">
<xml_orderline id="11" pid="11" name="bmw" />
<xml_orderline id="12" pid="11" name="mercedes" />
<xml_orderline id="13" pid="11" name="lada" />
</xml_order>
So, this part (creation) is working fine. But when it comes to editing the data within the attribute, it seems just doesn't change them.
sub change_data(id,pid,param,val)
dim domLine, domLines, xmlOrderItem, xmlOrder
set xmlOrder = Session("XML_ORDER")
On Error Resume Next
dim tmp : tmp = xmlOrder.getAttribute("id")
If Err <> 0 Then ' error occurred
set xmlOrder = xmlOrder.documentElement
End If
'RETRIEVE THE ORDERLINE BY collectionId
set domLine = xmlOrder.SelectSingleNode("//xml_orderline[@id='"& id &"' and @pid='"& pid &"']")
'UPDATE THE FIELD WITH THE NEW VALUE
domLine.setAttribute CStr(param),CStr(val)
' i am not sure whether the data is been modified by XMLDOM
' object automatically after I run setAttribute() method
' or is this all i have done here correct?
set Session("XML_ORDER") = xmlOrder
set domLine = nothing
set xmlOrder = nothing
end sub
Thank you very much in advance!
|