Jump to content
Sign in to follow this  

Reading XML

Recommended Posts


Hi I'm new to AutoIt and I was hoping I could get a little bit of help ;)

I'm building a form application which creates batch files for a renderer, so far things are going well but I'm stuck on one thing.

I need to look for cameras in a XML file and the user be able to select a camera from a list

in the XML the line looks like:

<Object Identifier="./Cameras/Scene 1" Label="Pinhole Camera" Name="Scene 1" Type="Camera">

"Scene 1" being the camera

There can be any amount of cameras in a scene,

If you need the actual xml


I'd be grateful for any help

if your interested the batch file creator is going to be a AutoIt version of this, I've got all the scene input, save, run done :)

Share this post

Link to post
Share on other sites

#include <String.au3>

$xml = FileRead('untitled.xml')

 $objects = StringRegExp($xml, '<Object(.*?)Type="Camera">', 3)
ConsoleWrite('Number of cameras in XML: ' & UBound($objects) & @CRLF)

For $i = 0 To UBound($objects) - 1
    $object = $objects[$i]
;~   ConsoleWrite('object: ' & $object & @CRLF)
    $name = GetValue($object, 'Name')
    ConsoleWrite('camera name: ' & $name & @CRLF)

Func GetValue($xml_data, $name_col)
    Return StringBetween($xml_data, $name_col & '="', '"')

Func StringBetween($sString, $sStart, $sEnd)
    $sReturn = _StringBetween($sString, $sStart, $sEnd) ;, -1, 1)
    If @error Then Return ''
    Return StringStripWS($sReturn[0],3)



Number of cameras in XML: 2

camera name: ## Current View ##

camera name: Scene 1

Edited by Zedna

Share this post

Link to post
Share on other sites


I suppose you should be able to get your data with a regular expression:

$text = '<Object Identifier="./Cameras/Scene 1" Label="Pinhole Camera" Name="Scene 1" Type="Camera">'
$aCameraList = StringRegExp($text, '(?i)<Objecth+Identifier="([^"]+)"h+Label="([^"]+)"h+Name="([^"]+)"h+Type="Camera"h*>', 4)
For $i = 0 To UBound($aCameraList)-1
    $aCamera = $aCameraList[$i]
    MsgBox(0, "", "ID: " & $aCamera[1] & @CRLF & "Label: " & $aCamera[2] & @CRLF & "Name: " & $aCamera[3])

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.