I need to change the attributes in an XML document with VBS

bormescosse

New Member
I have been all over the web looking for a clean way to change 2 attributes in an XML node using VBS (unfortunately my only choice for this with this client). The XML has a node in it that looks like this:\[code\]<lot id="ajhgkhga" lot="1" block="1" section="73R">\[/code\]I need to change it to this (and retain the rest of the XML document):\[code\]<lot id="ajhgkhga" lot="1" block="22" section="55">\[/code\]I have been hacking away at VBS most of the day and here is where I am now:\[code\] Dim objXMLDocDim objXMLElementDim objXMLNodeListDim numObjXMLNodeListDim iDim lotDim sectionDim attrset objXMLDoc = CreateObject("Microsoft.XMLDOM")objXMLDoc.async = "false"objXMLDoc.load("section73R.xml")Set objXMLNodeList = objXMLDoc.getElementsByTagName("lot")numObjXMLNodeList = objXMLNodeList.lengthFor i = 0 to numObjXMLNodeList - 1 ' current value of the block and section attributes of the lot element block = objXMLNodeList.item(i).getAttribute("block") section = objXMLNodeList.item(i).getAttribute("section") 'Wscript.Echo block & " " & section ' new value of the block and section attributes of the lot element objXMLNodeList.item(i).setAttribute "block", "22" objXMLNodeList.item(i).setAttribute "section", "55"Next\[/code\]This throws an error as indicated above. My VBS chops are barely existent at this point, I have not done it in a very long time. The code above is designed only to try to read the attributes, I figured that once I had that replacing the values wouldn't be too hard.Can anyone help me actually figure out how to replace those values? And in doing so show me how far off I am in this script? Thanks in advance!EDIT: I can now get the two attribute values out (see code change above). All I need now is a way to write the new attribute values to the XML file and this will be a done deal. Can anyone give me any pointers?EDIT #2: I was able to solve it pretty quickly once I was able to retrieve the attribute values and I have edited the code above.
 
Back
Top