PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
XML <nodeName> </nodeName> vs. <nameName />
A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: XML <nodeName> </nodeName> vs. <nameName />

Hybrid View

  1. #1
    Member
    Join Date
    Apr 2008
    Posts
    97

    XML <nodeName> </nodeName> vs. <nameName />

    I am not getting the same results when using XML that does not have dedicated closing node.

    The code runs and creates the aniClass or controlClass object, and inserts the object into the correct array, it just does not read the attributes.

    If I put <empty></empty>, then a </animation> or </control>, everything is processed correctly.

    WHAT AM I DOING WRONG?

    Code:
    //does NOT read attributes
    <animation c="animations.anotherExample" />
    <control c="controllers.anotherExample" />
    
    //process correctly
    <animation c="animations.ani978797">
    	<param name ="jump">
    		<value>15</value>
    	</param>
    </animation>
    <control c="controller.UG978797">
    	<param name ="blinkInterval">
    		<value>15000</value>
    	</param>
    </control >
    ActionScript
    Actionscript Code:
    private function parseMenu():void
            {
               
               
                var i:int = 0;
                var j:int = 0
                for each(var item:XML in _menu)
                {

                    //create a new menuItem and store it in the childMenuItems array
                    if(item.name() == "menuItem"){
                        var menuItem:DeviceMenuItem = new DeviceMenuItem(_menu[i] , j);
                        menuItem.parentMenuItem = this;
                        childMenuItems.push(menuItem);
                        //update j so each item has the proper index
                        j++;
                    }else if(item.name() == "animation"){
                        //add the animation(s)
                        addAnimation(item);
                       
                    }else if(item.name() == "control"){
                        //add the control(s)
                        addControl(item);
                       
                    }else if (item.name() == "textDisplay"){
                        //add the text
                        addText(item);
                       
                    }
                    //update i to reference the correct node in _menu
                    i++;
                }
            }
            private function addAnimation(ani:XML):void
            {
                for each(var animation:XML in ani)
                {              
                    var aniClass:Object = {};
                    //attribute class was reserved causing compile error, changed class to c
                    //sets the name of the class
                    aniClass.c =  String(animation..@c);
                   
                    //if there are no params, do not process
                    if(animation.param.length() == 0)
                    {
                        break;
                    }
                    //array used to hold the properties name and ....
                    var props:Array = new Array;
                   
                    for each(var parameter:XML in animation.param)
                    {
                        var prop:Object = {}
                       
                        prop.name = String(parameter..@name);
                       
                        //... and values
                        var values:Array = new Array();
                       
                        for each(var value:XML in parameter.value)
                        {
                            values.push(value.toString())
                           
                        }
                        prop.values = values;
                        props.push(prop);
                    }
                    aniClass.props = props;
                    _animationList.push(aniClass);
                }
               
            }
            private function addControl(ctrl:XML):void
            {
                for each(var controller:XML in ctrl)
                {              
                    var ctrlClass:Object = {};
                    //gets the class name from the attribute in the xml node c
                    ctrlClass.c = String(controller..@c);
                   
                   
                    //if there are no params, do not process
                    if(controller.param.length() == 0)
                    {
                        break;
                    }
                    //array used to hold the properties name and ....
                    var props:Array = new Array;
                    for each(var parameter:XML in controller.param)
                    {
                        var prop:Object = {}
                       
                        prop.name = String(parameter..@name);
                        //... and values
                        var values:Array = new Array();
                       
                        for each(var value:XML in parameter.value)
                        {
                            values.push(value.toString())
                           
                        }
                        prop.values = values;
                        props.push(prop);
                    }
                    ctrlClass.props = props;
                    _controlList.push(ctrlClass);
                }
                           
            }

  2. #2
    Junior Member
    Join Date
    Jun 2010
    Location
    Toronto
    Posts
    28
    I think you may need to surround everything with a root node, otherwise the parser get's confused. Also, the last node shouldn't have a space inside that way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center