Sunday, May 1, 2011

VB Script - Edit xml document.

VB Script - Edit xml document.

Recently I was performing a load test on Web service that consume XML document. The load test parameters are: upload 2000 XML files sequentially having different ID's (XML document contain  "PayloadID" and "OrderID" that should be unique). In order to create 2000 XML files with unique id's I have created following VB script.
Path = "C:\Documents and Settings\bharathm\Desktop\"
xmlfile=Path & "orginal.xml"    'your source file name
NumberOfFiles = 2
AppendString = "B"

set oparser=createobject("msxml2.domdocument")
with oparser
    .load xmlfile
end with
if oparser.parseerror.errorcode<>0 then
    wscript.echo "xml file " & xmlfile & " is not well-formed." & vbcrlf & "Operation aborted."
    wscript.quit 999
end if

for count = 1 to NumberOfFiles
 value = AppendString & count 'Unique string to update document
 set oroot=oparser.documentElement
 oroot.setAttribute "payloadID", value
 Set currNode = oparser.documentelement.selectSingleNode("//cXML/Request/OrderRequest/OrderRequestHeader")
 currNode.setAttribute "orderID",value
 outfile=Path & "TestFiles\" & value &".xml"   'create new output file with unique name outfile
set oparser=nothing 
wscript.echo "Completed"

I hope this post will help you in manipulating XML document and make duplicate copies.


No comments:

Post a Comment