Ultrashock Forums > Flash > Flash Professional
(AS2) XML - convert < to read as HTML

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
(AS2) XML - convert < to read as HTML
Old 2009-03-25

Hi,
I'm bringing in some XML from a PHP generated page. unfortunately they PHP generates the XML as follows:

Code:
<moreInfo>&lt;b&gt;Abstract Painting&lt;/b&gt;&lt;br /&gt;1963&lt;br /&gt;170.00 x 215.00
 cm&lt;br /&gt;Oil on canvas&lt;</moreInfo>
Rather than processing and reading the data as HTML, flash will print this out as html:

Code:
<b>Abstract Painting</b><br />1963<br />170.00 x 215.00 cm<br />Oil on canvas<br />
I'm using AS2, a HTML enabled text field and i've tried the unescape/escape function. It looks like unescape will only work on hexadecimal data.

Any ideas on how to get flash to read this as html?

Cheers,
Luke.
postbit arrow 4 comments | 1320 views postbit arrow Reply: with Quote   
Registered User
Luke.F is offline
seperator
Posts: 21
2005-08-01
Luke.F lives in Australia
Luke.F's Avatar
seperator

Ultrashock Member Comments:
chrismann chrismann is offline chrismann lives in United States 2009-03-25 #2 Old  
Edited (I found a possible solution)

Here's a test I ran
Code:
var m:String= "<items><one>plain</one><two><![CDATA[this is <i>italic</i>]]></two></items>";
var my_xml:XML = new XML(m);
trace("using firstChild:");
for (var i = 0; i<my_xml.firstChild.childNodes.length; i++) {
    trace("\t"+my_xml.firstChild.childNodes[i].firstChild);
}
trace("");
trace("using firstChild.nodeValue:");
for (var i = 0; i<my_xml.firstChild.childNodes.length; i++) {
    trace("\t"+my_xml.firstChild.childNodes[i].firstChild.nodeValue);
}
Output is
Code:
using firstChild:
	plain
	this is &lt;i&gt;italic&lt;/i&gt;

using firstChild.nodeValue:
	plain
	this is <i>italic</i>
Reply With Quote  
tiran tiran is offline tiran lives in United States 2009-03-25 #3 Old  
As you found out, the problem is not how PHP interprets the page, its how Flash does. Take a look at your raw php generated XML in a browser and you will not see those characters. nodeValue is the solution you are looking for.
Reply With Quote  
Luke.F's Avatar Luke.F Luke.F is offline Luke.F lives in Australia 2009-03-26 #4 Old  
almost there
Thanks for your help, this is looking good. It's returning "null" at the moment. Can you figure out what's happening? Here's what I've got:


AS2

ActionScript Code:
  1. moreInfoTxt.htmlText = mainNode.childNodes[moreInformation].childNodes[0].nodeValue


XML:

Code:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<songs>
	<song trackTitle="track tite1">  
		<moreInfo><![CDATA[ &lt;b&gt;Abstract Painting&lt;/b&gt;&lt;
br /&gt;1963&lt;br /&gt;170.00 x 215.00 cm&lt;br /&gt;Oil on canvas&lt;
br /&gt;Catalogue Raisonné: 144&lt;br /&gt;Collection: K21 Kunstsammlung, 
D&amp;uuml;sseldorf, Germany&lt;br /&gt;Audio courtesy of &lt;u&gt;&lt;
a href='http://:www.acoustiguide.com' target='_blank'&gt;
Acoustiguide&lt;/a&gt;&lt;/u&gt;]]></moreInfo>
	</song>
</songs>
(I've broken the xml apart so the forum page holds together)
Reply With Quote  
Luke.F's Avatar Luke.F Luke.F is offline Luke.F lives in Australia 2009-03-26 #5 Old  
Last edited by Luke.F : 2009-03-26 at 08:19.
Hi,
All fixed! Thanks for your help. I out that i was declaring a var that messed with it. Basically, nodeValue worked a treat.

Thanks UShock team.


full solution:
mainNode.childNodes[moreInformation].childNodes[0].nodeValue.split("&lt;").join("<").split("&gt;").join(">");
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: