Jump to content

manipulate an xml file

Recommended Posts


I have a xml file which i need to duplicate in to 100 copies with different random value for one identified tag. I only know little autoit. ( how to move mouse , keys so on and ui controls )

I thought of doing like below

  1. open the xml file
  2. navigate in to target xml tag with arrow keys.

Loop {

generate random number random() in to a variable. copy that in to clipbord.

paste it inside target tag (using ctrl+v)

invoke save as ->> paste the same random number to file name section

save the file



Please advice me how to achieve the section i marked in BOLD. (how to take generated random number in to a variable)

or are there any easy way to do it









Share this post

Link to post
Share on other sites

I think it would be easier to do it programmatically.  An xml tag should be fairly easy to find using regular expressions.  See the function StringRegExp() in the help.  You can use _FileReadToArray() to read the file.  The array will have a lone for each index.  Loop through using the line as the string for the regex compare.  When you find it substitute the randome value.  Then write the file back.

See the example scripts for each function in the help file.  If you mess around with them you should get the idea.  AutoIt3 syntax is very easy to pick up.  It is good as a firs programming language for Windows for that reason and others.  :)

If you get something partly working and get stuck post a snippet and someone will help get you over the hurdle.



Edited by MilesAhead

Share this post

Link to post
Share on other sites

Without more details, I can only point you at other forum posts...do a search for XMLDOM.

.load = load the xml

.save("newfile.xml") save to some new file (probably add an incrementer onto the name to make them unique.

You would only need to grab the element once, and then loop 100 times where you update the nodes .text with a random string you generate in the script.

Here is an example:

$xml = "<SomeXML>" & _
"<NodeWithRandomNumber />" & _

Local $oXML = ObjCreate("Microsoft.XMLDOM")
$oNode = $oXML.selectSingleNode("//NodeWithRandomNumber")

; create a folder to save to:
$sOutputFolder = @DesktopDir & "\xmlOutput"

For $i = 1 To 100
    $oNode.text = Random(10000,99999,1)
    $oXML.save($sOutputFolder & "\RandomXML" & $i & ".xml")
    ConsoleWrite($sOutputFolder & "\RandomXML" & $i & ".xml will include random number=[" & $oNode.text & "]" & @CRLF)


Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post

Link to post
Share on other sites


There as a couple of XML UDF's (User Defined Functions) in the Examples section of the forum. Both are probably fairly old now though, and you may need to search the forum using Google to find them, to wrestle with.

Personally, as you are only doing one value, multiple times, I would go with something like MilesAhead suggested.

If you whip up some code yourself and run into trouble, then post it here and we will set you straight.

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.


What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...