[Pixlib] XMLToObject

Cédric Néhémie cartel.com at free.fr
Thu Nov 17 09:01:38 EST 2005


Tell me if i'm wrong :

Here the code in revision 19, for each node in the root node you get 
object's name with name attribute or nodename if no name attribute. If 
name already exist you get one unique name based on current name.
Then you get type from attributes but if there's no type you define it 
as xml2o. And if it's an xml2o type the data is set with the entire 
node, else you use nodeValue (witch return null if nodes only contains 
subnodes) so you can't browse for children node...

 public function deserializeData(oXML:XMLNode, oL) : Object
    {
        var o:Object = new Object();
        for (var x = 0; x < oXML.childNodes.length; x++)
        {
            var sName:String = oXML.childNodes[x].attributes.name;
            if (sName == undefined) sName = oXML.childNodes[x].nodeName;
                   
            if ( o[sName] )
            {
                Logger.LOG( "XMLToObject parsed two nodes with identical 
names : '" + sName + "'.", LogLevel.WARN);
                sName = _getUniquePropName(o, sName);
            }
           
            o[sName] = {};
                  
            var sType:String = oXML.childNodes[x].attributes.type;
            if (sType == undefined) sType = "xml2o";
            o[sName]["varType"] = sType;
            o[sName]["data"] = (sType != "xml2o") ? 
oXML.childNodes[x].firstChild.nodeValue : oXML.childNodes[x];

        }
       
        for(var p:String in o) _oDeserializer.deserialize(oL, p, 
o[p].varType, o[p].data, this);
        return oL;
    }

Francis Bourre a écrit :

>Hello Cedric!
>
>"xml2o" is an old behavior which was available long time ago before 
>deserializer's introduction in rev14.
>It's been deprecated, but I kept the old code implementation behind the 
>scenes to keep some compatibility with old projects.
>Important: You don't need any "xml2o" attribute to get Object type now. ;) 
>Any node nesting some other nodes will be automatically casted as an Object.
>
>About "type" attribute, it's there coz in my design choice, node names are 
>automatically transformed to properties names.
>In a future version of XMLToObject, (pixLib for AS3), there will be no need 
>of "type" attributes. I use ECMAScript notation to cast the good type.
>
>Hope that helps,
>
>francis
>
>----- Original Message ----- 
>From: "Cédric Néhémie" <cartel.com at free.fr>
>To: "Mailling PixLib" <Pixlib at osflash.org>
>Sent: Thursday, November 17, 2005 9:12 AM
>Subject: [Pixlib] XMLToObject
>
>
>  
>
>>Hi Francis,
>>
>>Something seems strange in XMLToObject.deserializeData, the line :
>>
>>o[sName]["data"] = (sType != "xml2o") ?
>>oXML.childNodes[x].firstChild.nodeValue : oXML.childNodes[x];
>>
>>if type of the node is not xml2o you use nodeValue to set the data
>>field. I think that is not to XMLToObject to choose witch of nodeValue
>>or childNodes use to fill data. The XMLToObjectDeserializer is more
>>approriate to that task, and that let us choosing xml structure.
>>
>>Another strange thing is that you have preferred use a "type" attribute
>>to switch deserializer's behaviour instead of nodename, why have you
>>decided to chose this alternative?
>>
>>Regards
>>
>>Cedric
>>    
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/pixlib_osflash.org/attachments/20051117/d8f42d41/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cartel.com.vcf
Type: text/x-vcard
Size: 219 bytes
Desc: not available
Url : http://osflash.org/pipermail/pixlib_osflash.org/attachments/20051117/d8f42d41/cartel.com-0001.vcf


More information about the Pixlib mailing list