You're running into a difference between an XMLList (a
built-in E4X type, along with the XML type) and XMLListCollection (a Flex
framework type).
If the right-hand-side (RHS) of the E4X += operator is an
XML instance or an XMLList instance, it inserts children as you are expecting.
For example, suppose var x:XML = <a><b/></a>.
Then x.b += <c/> sets x to <a><b/><c/></a>.
(This is the case where RHS is an XML instance.)
And x.b += <><c/><c/></> sets x to
<a><b/><c/><c/></a>. (This is the case where RHS
is an XMLList instance.)
(Note that you can't write an XMLList literal as
<c/><c/>; it doesn't compile. You wrap the nodes of the list
between <> and </>.)
However, if the RHS is any other type, then it calls
toString() on the RHS and inserts it as text, not as child nodes.
For eample, x.b += "foo" sets x to
<a><b>foo</b></a>.
You can't have < and > in XML text, so they get
converted to the XML escape entities < and >
For example, x.b += "<c/>" sets x to <a><b><c/>
</b></a>.
Since E4X doesn't know about XMLListCollection, it treats it
like any other type and converts your XMLLC to a string and then escapes it. I
don't know of any way to directly convert an XMLListCollection to an XMLList
without looping over the items, which is similar to what you're doing extract
one XML from the XMLListCollection at a time.
- Gordon
From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Luis Eduardo
Sent: Wednesday, October 25, 2006
12:33 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] +=
operator is changing the encodings
Igor,
thx for your answer, but i think something isnt clear...
my problem is on the += operator in this line of code:
xgravar.root.request += XMLLC;
the XMLLC object is declared as:
<mx:XMLListCollection id="XMLLC"
collectionChange="collectionEventHandler(event)"/>
and have, at the time this line of code fire, the follow XML
<TipoVeiculo Id="1" Nome="Moto"
Descricao="desc">
<TipoVeiculo Id="2" Nome="Carro"
Descricao="desc">
<TipoVeiculo Id="3" Nome="Caminhao"
Descricao="desc">
<TipoVeiculo Id="4" Nome="Aviao"
Descricao="desc">
just that. (without a root node).
the root node is at "xgravar.request".
but, when i do:
xgravar.root.request += XMLLC;
and after Alert.show(xgravar.toXMLString()) the code is changed to:
<ds>
<root>
<request>
<TipoVeiculo Id="1" Nome="Moto"
Descricao="desc">
<TipoVeiculo Id="2" Nome="Carro"
Descricao="desc">
<TipoVeiculo Id="3" Nome="Caminhao"
Descricao="desc">
<TipoVeiculo Id="4" Nome="Aviao"
Descricao="desc">
</request>
</root>
</ds>
i have made a workaround for this with the follow code:
for each( var item : XML in XMLLC ) {
XML(xgravar.root.request).appendChild(item);
}
but i think that the += operator SHOULD do the same thing WITHOUT
changing the < and > simbols.
dont you agree?
best regards to you!
Luís Eduardo.
Igor Costa escreveu:
> Hi Luiz
>
>
> Isn't the operator that's wrong, you just missed out how to pass
> String and concatening in both side of wall.
>
> Check out this heck of how could be done.
>
> public function myList():void
> {
> var myXML = new
> XMLList("<dsRQ><root><request/></root></dsRQ>");
> szCommand = "insert";
> if( xgravar.request.@command = szCommand == true)
> {
> Alert.show(xgravar.toString());
> }
> else {
> Alert.show(xgravar);
> }
> }
>
>
> The problem is, you are trying to convert an object twice in time in
> the same function, that's why the problem happens. if you put anything
> in braces <> than you convert to string, the compiler intend to
> undrestand that, "ok the users now want to convert that cacharecter".
>
>
> Regards.
>
> szCommand = "insert";
> xgravar.root.request.@command = szCommand;
>
> Alert.show(XMLLC.toXMLString()); // OK here. all < and >
> works fine
>
> xgravar.root.request += XMLLC;
>
> Alert.show(xgravar.toXMLString()); // ERROR here. < and >
> converted to < and >
> }
>
>
>
>
>
>
>
> On 10/24/06, *Luis Eduardo* <illogic_code@yahoo.com.br
> <mailto:illogic_code@yahoo.com.br>>
wrote:
>
>
> hi,
>
> In my app, when i use the += operator, the data inside xmls turns
> with
> diferent encoding.
> The < and > caracters become wierds like < and >
respectively.
>
> How can i fix this?
>
> this is the code:
>
> public function doGravar():void {
> var xgravar:XMLList = new
> XMLList("<dsRQ><root><request/></root></dsRQ>");
>
> szCommand = "insert";
> xgravar.root.request.@command = szCommand;
>
> Alert.show(XMLLC.toXMLString()); // OK here. all < and >
> works fine
>
> xgravar.root.request += XMLLC;
>
> Alert.show(xgravar.toXMLString()); // ERROR here. < and >
> converted to < and >
> }
>
> where XMLLC : XMLListCollection and szCommand : String.
> The first Alert will show correct data but the second will show
> caracters converted.
>
> regards,
>
> Luís Eduardo.
>
>
> _______________________________________________________
> Novidade no Yahoo! Mail: receba alertas de novas mensagens no seu
> celular. Registre seu aparelho agora!
> http://br.mobile.yahoo.com/mailalertas/
> <http://br.mobile.yahoo.com/mailalertas/>
>
>
>
>
>
> --
> ----------------------------
> Igor Costa
> www.igorcosta.com <http://www.igorcosta.com>
>
_______________________________________________________
O Yahoo! est de cara nova. Venha conferir!
http://br.yahoo.com
__._,_.___
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
__,_._,___