Glen,
   The backend shouldn't care about element order. :-)

   That'd be my take on it, if you're just using the XML to exchange a
simple set of properties rather than (say) using it to present a
structured document where the order is crucial to how it's read.

   If you _do_ care about the order (and I really don't think you
should have to), you need to store a sort order for each key. I've no
idea how you are generating the parameters or the order, but it might
be as simple as:

var keys:Array=["someParam","someOtherParam","someThirdParam"];
for each (var key:String in keys)
{
  var parXML:XML = <{key}>{params[key].toString()}</{key}>;
  cmd.command.parameters.appendChild(parXML);
}

But that sort of hard-coding feels totally wrong, and makes me think
that there is too much hardcoding going on at the C++ end.

Ian

On Thu, Aug 27, 2009 at 3:43 PM, Glen Pike<[email protected]> wrote:
> Hi,
>
>   I have a project where we are passing XML via a socket to a C++ based
> server and there is an issue with the ordering of XML elements inside a
> packet.
>
>   In AS3, I am assembling a packet with a <parameters> element that contains
> 1 or more children with <name>value</name> type syntax.  Because the
> "params" are passed into a generic function, I am looping through an object
> as follows:
>
>   //if params, loop through params, create params.
>           if (null != params) {
>               cmd.command.appendChild(<parameters/>);
>               for (var par:* in params) {
>                   //var val:String = ;
>                   var parXML:XML = <{par}>{params[par].toString()}</{par}>;
>                   cmd.command.parameters.appendChild(parXML);
>               }
>           }
>
>   The C++ guy is asking if I can send these parameters in a specific order,
> but I can't see any way to guarantee that order without hardcoding, or using
> an indexed array, which implies hardcoding somewhere else.
>
>   Does anyone know of a way to do this - I suppose I could loop through the
> object, get the property "keys", sort these, then loop through the result to
> read values, but guessing thats the only way.
>
>   I could also argue that the back end needs to use an XML parser that does
> not care about element order, so if anyone has any tips on that, it would be
> appreciated.
>
>   Ta
>
>   glen
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>

_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to