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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Apply HTML tags to dynamic text from XML

Status
Not open for further replies.

digitalpencil

Programmer
Apr 8, 2001
165
GB
Hi guys,
Hoping one of you can help me understand how to apply HTML formatting to dynamic text sourced from an XML doc.
I've looked online but am getting pretty confused. Something to do with wrapping the HTML tags in CDATA? and then doing the same in the AS? then 'joining' them..
As i said, i'm pretty confused.
I imagine this is the easiest thing in the world and I, as usual, am just being thick.

Any ideas? let me know,

Thanks ;)
 
You can't have HTML tags in an XML node because HTML tags are treated as XML tags. One way to deal with this is to put the HTML text in CDATA:
[tt]
<?xml version="1.0" ?>
<htmlText>
<![CDATA[
Some <b>HTML</b> text here.
]]>
</htmlText>
[/tt]
Then you can apply the nodeValue to a TextField.htmlText property easily.

Kenneth Kawamoto
 
Thanks Kenneth, but I've attempted this and it has not worked, I think because of the formatting of my XML. I'm new to all fo this and am using a a tutorial file as a template which I think involves attributes.
My XML is as follows:
<?xml version="1.0" encoding="iso-8859-1"?>
<description>
<entry
name="Some text."
/>
How would I go about, say applying a bold tag to "text" in the above?

I'm not sure if you require the AS to understand but on the off-chance:
//-----------LOAD DESC XML------------------
var contacts = new XML();
contacts.ignoreWhite = true;
var entry = 0;
var total = 0;
var current = 0;
contacts.load("desc.xml");
contacts.onLoad = function(success) {
if (success) {
controllerMC.name_txt = this.firstChild.childNodes[_root.entry].attributes.name;

_root.total = this.firstChild.childNodes.length;
_root.current = _root.entry + 1;
controllerMC.entryNum_txt = _root.current+" of "+ _root.total;
}
};

Thanks again,
Digi
 
First of all, you cannot have HTML tags in XML attributes. Also Flash reads XML as UTF-8 or UTF-16 by default. Therefore you may want to change your XML to something like:

<?xml version="1.0" encoding="utf-8"?>
<description>
<entry>
<name><![CDATA[Some <b>text</b>]]></name>
</entry>
</description>

Kenneth Kawamoto
 
Ahh ok, beginning to make sense, but then I would surely need to change my AS to reflect the lack of an attribute, yes?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top