AS3 xml string and < > problems
- Started
- Last post
- 7 Responses
- felizfeliz
can anyone help with the following:
I have an xml document that I've loaded into flash, I then replace the text in one 'node', for example, from this in my xml document:
<TITLE><![CDATA[Hello]]></TITLE>I replace like this in Actionscript:
myxml.root.title = "<![CDATA[Test]]>";when I trace "myxml.root.title" I get this:
<![CDATA[Test]]>
which is perfect.
But when I trace the whole xml I get this:<root>
<TITLE>& lt;![CDATA[Test]]& gt;</TITLE>
</root>Why?!!!!!! why is it converting "<" to "& lt;" and how can I stop it doing that! I've search google but can't find an answer.
Thanks in advance!
- creez0
"<" is forbiden in xml
- cannot be inside an XML elementcreez
- unless you use CDATA.anxious_arms
- felizfeliz0
hmm.. but if i create a xml document in a text editor i can use "<![CDATA[Test]]>" so why can't i do that within flash when creating an xml document(i later send the xml document to a php script that saves it onto my server)? what's the solution?
- acescence0
flash just sees your assignment as a text string. also, the flash xml parser does not handle cdata the same way as the browser's xml parser, it just converts them to regular text nodes.
- felizfeliz0
so should I convert < to < in my php script that saves the xml data from flash to an xml file?
how do i do that? is there a php equivalent to split("<").join("<") ?
- NONEIS0
Unless you are using those nodes to include markup / syntax (based on your example it look slike basic strings...), there is no reason to use CDATA in the first place. CDATA is only useful when preserving code in an XML node.
- felizfeliz0
ah thanks everyone, i've figured it out - i'm just converting the < back to < etc in the php script:
$xml = str_replace("<", "<", $xml);
$xml = str_replace(">", ">", $xml);and i need to use CDATA as i'm using css tags to style the xml loaded text.