Re: [flexcoders] Re: Encoding XML Character Entity References *properly*

2010-08-23 Thread Oleg Sivokon
Both your variants are... strange... you use literal and create a new object
by passing it an already created object...

var xml:XML = {bar};

This is how you'd normally do it. E4X uses couple of special opcodes
allocated only for it, so, my guess that using E4X expressions for
constructing XMLs should be the right way to do things. If you parse XML at
runtime, as opposed to the first way you bypass the compiler XML validation,
which is in generall a not smart thing to do... So, my guess that either
your test was somehow wrong, or, even if it was precise, then the benefit of
having compile time verification of XML structure would overweight in the
end. I don't believe the difference, even if not in favor of E4X may be that
big to consider reproducing it "by hand".


Re: [flexcoders] Re: Encoding XML Character Entity References *properly*

2010-08-22 Thread dorkie dork from dorktown
 var x:XML = new XML();
var b:String = "a string/&  lkj l";
x.appendChild(b);
textarea.text = x.toXMLString();

does this work for you? it is for me. also what SDK FP version are you
using? are you using as3corelib? there is an xmlutil.isvalid method that you
can use


On Thu, Aug 19, 2010 at 8:21 AM, pmorch  wrote:

>
>
> I figured it out:
>
>
> > new XML("" + xmlEscape(string) + "");
>
> is better done as:
>
>
> > new XML({string});
>
> See also:
> http://stackoverflow.com/questions/1856726/how-do-you-encode-xml-safely-with-actionscript-3/
>
>  
>


[flexcoders] Re: Encoding XML Character Entity References *properly*

2010-08-19 Thread pmorch
I figured it out:

> new XML("" + xmlEscape(string) + "");

is better done as:

> new XML({string});

See also: 
http://stackoverflow.com/questions/1856726/how-do-you-encode-xml-safely-with-actionscript-3/



[flexcoders] Re: Encoding XML Character Entity References *properly*

2010-02-05 Thread valdhor
Try this:

private function htmlEscape(str:String):String
{
 return XML(new XMLNode(XMLNodeType.TEXT_NODE, str)).toXMLString();
}

It uses the legacy ActionScript 2 object. I don't know how long this
will stay around but it is included in the latest 3.5SDK (Not sure about
4).

HTH



Steve

--- In flexcoders@yahoogroups.com, Peter Valdemar Mørch 
wrote:
>
> Hi, I didn't get any replies, so here is a polite bump...
>
> My question is basically this: How do I create an XML node with a
> toXMLString() value of:
>
> a string/&
>
> from a value of
>
> var value:String = "a string/&";
>
> Is this really something one is expected to code by hand using RegExp
> or split&join? Isn't this something everybody who needs to send /
> recieve XML needs to be safe? I just can't find it anywhere.
>
> Also, I wrote:
> > P.S.: Please don't tell me about escape() because it URL-encodes,
> > which is not the same thing. (For "a&b" I want "a&b", not
> > "a%26b).
>
> Sorry if this offended anyone. I didn't mean to be rude.
>
> Peter
> --
> Peter Valdemar Mørch
> http://www.morch.com
>