What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [Help] Enumerating XML nodes...

[Help] Enumerating XML nodes...
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [Help] Enumerating XML nodes...
You could use some recursion for that. :P
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 ;
}
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
11-17-2009 06:42 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[Help] Enumerating XML nodes... - by whiz on 11-16-2009 at 07:14 PM
RE: [Help] Enumerating XML nodes... - by matty on 11-16-2009 at 07:27 PM
RE: [Help] Enumerating XML nodes... - by whiz on 11-16-2009 at 07:36 PM
RE: [Help] Enumerating XML nodes... - by Matti on 11-17-2009 at 06:42 PM
RE: [Help] Enumerating XML nodes... - by matty on 11-17-2009 at 07:08 PM
RE: [Help] Enumerating XML nodes... - by whiz on 11-18-2009 at 03:22 PM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On