all groups > flash actionscript > october 2007 >
You're in the

flash actionscript

group:

XML / TextField problem : Displaying escaped quotation marks


XML / TextField problem : Displaying escaped quotation marks stephan.k
10/19/2007 8:35:12 PM
flash actionscript:
Dear Forum

I am having problem displaying escaped quotation marks in a dynamic text
field. I'm using flash 8. Actionscript 2.

1) I am loading the text content from a database / php with XML. It looks
like this (note the backslashes!):

--------------------------------------------------------------------------------
-------------------------------------------------------
[...]
<description><![CDATA[My sample description text conains \"quotation marks.\"
]]></description>
[...]

2) After successfully loading the XML, I am retrieving the XML Node value
like this:

--------------------------------------------------------------------------------
------------------------------
[...]
descriptionTXT =
String(xml.firstChild.childNodes[0].childNodes[3].firstChild.nodeValue);
[...]

3) Then I fill in the text into the TextField on the Stage, which has been put
there manually. The HTML button of the text field is on and all the necessary
fonts are installed (punctuations, all latins and regular characters)

--------------------------------------------------------------------------------
-----------------------------------------------------------
_root.txt_description.html = true;
_root.txt_description.htmlText = descriptionTXT ;

4) BUT the text field displays the text just like the XML file WITH the
backslashes:

--------------------------------------------------------------------------------
-----------------------------
My sample description text conains \"quotation marks.\"



Any ideas / suggestions how I can properly display the backslashes in flash 8?
or do I first need to do something with the text in php?

Thanks

Stephan






Re: XML / TextField problem : Displaying escaped quotation marks kglad
10/19/2007 8:57:03 PM
Re: XML / TextField problem : Displaying escaped quotation marks stephan.k
10/19/2007 9:02:41 PM
Re: XML / TextField problem : Displaying escaped quotation marks kglad
10/19/2007 9:10:22 PM
you do that in your xml file. instead of a quotation mark use:

Re: XML / TextField problem : Displaying escaped quotation marks stephan.k
10/19/2007 9:24:01 PM

I see. Since I am getting the XML content from a database what is the process
called that turns \" (backslash with quotation mark) into "(quotation mark),
which I could then urlencode with php?

And what would I need in flash to properly display that? I have used htmlText
and everything else as mentioned above but I get the url encoded string (a lot
of garbled numbers and %%...)




Re: XML / TextField problem : Displaying escaped quotation marks stephan.k
10/19/2007 9:27:14 PM
Re: XML / TextField problem : Displaying escaped quotation marks stephan.k
10/19/2007 10:02:48 PM
I've researched and tried a few things and this seems to do the trick:

"getContent.php"
-----------------------
print " <description>
<![CDATA[".urldecode(stripslashes($row{'Description'}))."]]> </description>\n";

Not sure if it'll cause any other issues. Again I've used
mysql_real_escape_string before putting the content into the database and when
retrieving it with php and formatting it as XML I am using stripslashes and
urldecode functions...

If there are cleaner sollutions please let me know. This urlencoding stuff is
confusing me a little....

Thanks

Stephan

Re: XML / TextField problem : Displaying escaped quotation marks GWD
10/19/2007 10:11:45 PM
You needed stripslashes to get rid of the slashes. Your content wasn't
urlencoded...but it probably makes sense to do urldecode as well....
My understanding is that the whole point of CDATA is you get exactly what's
there... there is no escaping etc. Its treated as raw character data. So you
just put the quotes in as:" no escaping or html entities needed.
Re: XML / TextField problem : Displaying escaped quotation marks stephan.k
10/19/2007 10:17:14 PM
got it. Thanks for the insight and your help. I appreciate it as always.

Best

Re: XML / TextField problem : Displaying escaped quotation marks kglad
10/19/2007 10:19:07 PM
Re: XML / TextField problem : Displaying escaped quotation marks GWD
10/19/2007 10:23:59 PM
kglad: with CDATA you use XML - you want a particular node with raw character data. If you just want raw character data and no other XML nodes, then yes you would use onData.

Re: XML / TextField problem : Displaying escaped quotation marks kglad
10/19/2007 10:30:17 PM
thanks gwd.

Re: XML / TextField problem : Displaying escaped quotation marks GWD
10/19/2007 10:32:08 PM
kglad: no you'll get " from CDATA if that's what it contains...I just tested it.
Re: XML / TextField problem : Displaying escaped quotation marks GWD
10/19/2007 10:43:08 PM
Re: XML / TextField problem : Displaying escaped quotation marks kglad
10/19/2007 11:36:48 PM
no, i meant if you trace(this) inside your onLoad method, you'll see something like

'

instead of

Re: XML / TextField problem : Displaying escaped quotation marks GWD
10/20/2007 12:00:00 AM
kglad: oh, yes, that's exactly what I demo'ed above, sorry but I misinterpreted
what you said originally - the code I posted supports exactly what you said.

trace calls the toString() method on the underlying XMLNode object and what
was originaly the CDATA node is converted back to regular textNode
representation rather than re-created as a CDATA node representation. This is
because flash/as2 only supports element and text nodes in its internal
representation so the CDATA node type is not retained after parsing. I haven't
tested that in as3 but it looks like it would be the same as there are only the
same 2 nodeTypes listed in the docs. So CDATA works going in, but not on the
way out of flash, if you needed that you would need to do that via string
methods I guess.


Re: XML / TextField problem : Displaying escaped quotation marks kglad
10/20/2007 2:54:27 PM
Re: XML / TextField problem : Displaying escaped quotation marks GWD
10/20/2007 7:13:14 PM
kglad: way I figure it, I would get involved (at most) in less than 5% of the
threads you post in - and only where I feel I have something to contribute
beyond what's already there...so that's already rare. But I pretty much read
all your posts to learn stuff, so I'd be pleased to think I gave something
back..
The reality is - I 'learnt' this myself a month or so back solving someone
else's problem in the forum here where they didn't have the right path to the
CDATA nodeValue. I'd never used CDATA before although I was vaguely aware of
it. Before that I had been pulling html in via xml the hard way, but after that
I realised that was the best way to do it. So for me it is also a recent
acquisition.

stephan.k: I hope its all working.
Re: XML / TextField problem : Displaying escaped quotation marks stephan.k
10/20/2007 7:28:38 PM
Thanks GWD and kglad for all the insight. It's all working. I appreciate your help.

Enjoy the weekend.

Cheers

Re: XML / TextField problem : Displaying escaped quotation marks GWD
10/20/2007 7:40:13 PM
Stephen: great to hear! You too (enjoy your weekend).
cheers
Re: XML / TextField problem : Displaying escaped quotation marks kglad
10/20/2007 9:25:44 PM
AddThis Social Bookmark Button