You could use some recursion for that.
The following code should enumerate all windows
and all controls in those windows
and all the children in those controls. Accessing such an element could then be done like this:
js code:
var Windows = EnumWindows("Interfaces.xml");
var ImageName = Windows["WndTest"].Controls["BtnOk"].Children["Image"].Name.Text;
Debug.Trace(ImageName);
WARNING! Untested code! Try it out and tell me whether it works.
js code:
/*
Enumerates all windows in a file with all their controls
*/
var objWindows = { } ;
function EnumWindows ( File ) {
// Load the XML from the specified file
var XML = new ActiveXObject ( 'MSXML.DOMDocument' ) ;
XML.async = false ;
XML.load ( File ) ;
// Loop through all of the windows
var Windows = XML.selectNodes ( '/Interfaces/Window' ) ;
for ( var i=0 ; i<Windows.length ; i ++) {
// Get the current window
var Node = Windows [ i ] ;
// Create a new object
var objWindow = { } ;
objWindow.Id = Node.getAttribute ( 'Id' ) ;
objWindow.Controls = EnumControls( Node ) ;
// Add to collection
objWindows [ Id ] = objWindow;
}
// Return all windows
return objWindows ;
}
function EnumControls ( Window ) {
var objControls = { } ;
// Loop through all of the controls
var Controls = Window.selectNodes ( '/Controls/Control' ) ;
for ( var i=0 ; i<Controls.length ; i ++) {
// Get the current control
var Node = Controls [ i ] ;
var Id = Node.getAttribute ( 'Id' ) ;
var Type = Node.getAttribute ( 'xsi:type' ) ;
// Create a new object
var objControl = { } ;
objControl.Id = Id ;
objControl.XsiType = Type ;
if( Node.hasChildNodes() ) objControl.Children = EnumControlChildren ( Node ) ;
// Add to collection
objControls [ Id ] = objControl ;
}
// Return collected controls
return objControls ;
}
function EnumControlChildren( Node ) {
objChildren = { } ;
// Loop through all of the children
var Children = Node.childNodes ;
for( var i=0; i<Children.length; i ++) {
// Get the current child
var Child = Controls [ i ] ;
var NodeName = Child.nodeName ;
// Create a new object
var objChild = { } ;
objChild.TagName = Child.nodeName;
// Enumerate all attributes
var Attrs = Child.attributes;
for( var j=0 ; j<Attrs.length ; j ++) {
var Attr = Attrs [ j ] ;
objChild [ Attr.name ] = Attr.text ;
}
// Enumerate all children through recursion
if( Child.hasChildNodes() ) objChild.Children = EnumControlChildren ( Child ) ;
else objChild.Text = Node.text;
// Add to collection
var NodeId = Child.getAttribute ( 'Id' ) ;
if(NodeId !== null) objChildren [ NodeId ] = objChild ;
else objChildren [ NodeName ] = objChild ;
}
// Return collected children
return objChildren ;
}