Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML CDATA Entity Problem 1

Status
Not open for further replies.

Shaggs

Programmer
Aug 26, 2003
25
AU
G'day,

I'm getting data from a web service style ASP page using an XML Object and whenever i get the xml back into flash all the special characters in the cdata/text nodes have been converted into entities e.g. < converted to &lt;.

This is a problem as i'm getting html text from a db and displaying it in textfields and as you can imagine the html shows in the textfields rather that formats the surrounding text. I'm a bit of a flash newb so i haven't encountered this before and in general browsers have no problems rendering entities so why not the bloody flash textfield objects. sorry no offence intended flash gurus.

i could tackily text replace the entities with thier requisite characters but this will be rather inefficient and I would rather come up with a more suitable solution.

Wondering if anyone else has encountered this problem and how they got around it.

thanks in advance

Shaggs
 
If you're directly using the XML object in Flash this shouldn't be a problem but if you're loading the data via loadVars you'll need to unescape the returned data:

Code:
lv.onLoad=function(){
var myXMLData:XML=new XML(unescape(this));
}
 
I'm using an XML objects sendAndLoad method and transversing the returned document using another xml object.

Perhaps this problem i'm having bears no relation to the flash xml classess but rather a server side problem MSXML2.DOMDocument's CDATA tag converts these characters, so they dont invalidate the xml document. However, I still have a hunch that flash's xml objects would do the same, they have to otherwise as mentioned before the document could potentially be invalid xml.

Also, the characters converted are not in escaped url format, rather entity format. The same format that is required in xsl documents etc.

for example if you wrote
<code>
trace(escape('&lt;'));
</code>
the output would not be < it would still be as above.

For the moment i have left the problem and done some text substitutions.

I'd still be very interested if anyone else had any comments
 
If you use the loadVars object instead of the XML sendAndLoad to grab the data initially you can certainly work around the problem by then converting the escaped string to XML, this is something I've done in the past and CDATA nodes then read correctly.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top