Possible gotcha with the XML class, but I'd like to get this confirmed if anyone has a second to try this out.
It seems that the XML class is converting " to its literal ASCII representation (i.e. the quote mark ") when converting a String into a new XML object. I'm sending this data over XML-RPC and I cannot have quotes being sent as plain-text, they need to be XML/HTML encoded.
Here's a quick test that shows it:
var str:String = "<string>Here is some text, with an image... <img src="http://www.google.co.uk/intl/en_uk/images/ logo.gif" /></string>"; var xml:XML = new XML( str ); trace( xml );
At this point I'd be sending the xml object over the wire with HTTPService. The problem is that trace()/Charles/Fiddler etc is showing that the " is being converted to a real quote (literal) and that can cause a problem with the server which wants encoded copy, and being XMLRPC, I cannot use CDATA in this case. This is not the same behaviour as appears in Flash 8, it also appears that it differs when compiling with the Flex SDK and the Flash CS3 IDE in terms of whether it also turns the < and > entities to their literal representations.
Does anyone know a workaround for this? Can it be expected behaviour? I think I'll have to be sending things as a string internally to avoid the problem for now but it would be good to hear other opinions.
Follow me on Twitter
trace(xml.toXMLString());
it still doesn't do the quotes though ;(
as mentioned trace(escape(xml)); may be your best bet...
The only solution I can see right now is to double HTML encode it, so that would be an &quot; for a quote mark. However I still think it's working differently between the compilers, and both are different to Flash 8's behaviour. Still looking into it.
var imgTag:XML = ;
var xml:XML = Here is some text, with an image { imgTag };
trace( xml );
var ur:URLRequest = new URLRequest('http://myserver.com');
var uv:URLVariables = new URLVariables();
uv.param = xml.toString();
ur.data = uv;
trace(ur.data)
---
Seems to work for me..
http://out.chewtinfoil.com/rlXML.txt
Thanks for your sample. Unfortunately I'm not using e4x directly within ActionScript as per your example, the XML is originally dynamically generated as a string (or loaded from elsewhere) and then converted to an XML data type. My posted example probably didn't reflect the situation fully.
So the problem is with the conversion that occurs in the XML constructor/parsing. It doesn't want to preserve the quote entity and there are no flags to allow you to keep it.
I have a somewhat reverse problem. I cannot get toXMLString() to output CDATA in a CDATA block. It outputs the escaped equivalent. So I can't put ActionScript source code into a CDATA and have it be legible coming back out of the XML object. If anyone figures out how to do this, let me know.
This is correct... A fully functional XML-RPC server should support unescaped quote marks in text nodes. But I was thrown by the commentary on:
http://www.w3schools.com/xml/xml_cdata.asp
Which suggests it is a good practice to encode those entities. So all in all, I don't have a problem at present, I just wanted the data to be the same as the server generated content which does use ". The CDATA scenario on the other hand definitely looks to be an issue. Do you have a sample online?
Here's a simple test:
var script:String = "trace(1 < 2 && 2 > 1)";
var str:String = '';
var xml:XML = new XML( str );
trace( xml.toXMLString() );
-- AS3 Output --
1)]]>
-- JSFL Output --
trace(1 < 2 && 2 > 1)
>
hope all the characters make it through ok.
<script><![CDATA[trace(1 < 2 && 2 > 1)]]></script>
Just for anyone else reading... I think that code might be:
var script:String = "<script><![CDATA[trace(1 < 2 && 2 > 1)]]></script>";
Thanks for bringing this up though Robert, hopefully someone finds this when wondering why the E4X is behaving differently in JSFL compared to in AS3.
Just noticed you posted that code snippet at "13:37"... nice ;)
I was try his test - it's work
A small xml is easy using URLVariables.
But my problem is send a big xml.
Using URLVariables the browser says "URL TOO LONG".
Must be another way...
In Adobe Flash forum no one answer this question.
I think Macromedia gave more attention to developers...