View Full Version : load html formated text from XML
enrique550
08-27-2004, 04:30 PM
Hi, Im using a component that reads the label and the data of a comboBox from an xml file.
the XML structure is like this:
<ITEMS>
<ITEM>
<LABEL>this is the label</LABEL>
<DATA>this is the data</DATA>
</ITEM>
<ITEMS>
I want to html-format the DATA part, for example:
<DATA><b>this</b>...</DATA>
In flash, I created a textbox with html enabled to read this field but it just doesnt pick up the html.
In dreamweaver I see it syntax-colors the html attributes but if I put "" around the text, then flash doesnt read the DATA at all.
So, how can I do this?
(hope you understand)
gracias again,
Gustavo
JEBoothjr
08-27-2004, 05:01 PM
Use CDATA. Example: <DATA><![CDATA[<b>this</b>]]></data>
You'll have to change your xml pathing to get the nodeValue, though. Example: myXML.firstchild.childNodes.nodeValue
enrique550
08-27-2004, 05:27 PM
cool,
thanks J.
Hi Gustavo,
You could also create the HTML on the fly, so-to-speak, with the data from the XML being placed within the tag that you wish to use. For example, your XML data is loaded into an array, and the Nth item (ie the one you want to apply the styling to) is placed in a string. Like..
var xmlData:Array = new Array();
// store the data in an array
// and add your XML data into array items
.
.
var convert_str:String = new String();
// to contain the XML data to be used
var htmlTag1_str:String = new String();
// to contain the opening tag(s)
var htmlTag2_str:String = new String();
// to contain the closing tag(s)
var displayText_str:String = new String();
// to contain the entire string
convert_str = xmlData[n];
//where n is the item you wish to use
htmlTag1_str = "<b>";
htmlTag2_str = "</b>";
displayText_str = htmlTag1_str.concat(convert_str, htmlTag2_str);
// concatenate the strings into one
.
.
myTextField_txt.htmlText = displayText_str;
// set it to display the whole string
although there may be a tidier way of coding it ;)
That way, at least the XML is only data, and not styling as well. But yes, <![CDATA[..]]> would work fine.
enrique550
08-27-2004, 06:48 PM
James,
I just read that the CDATA thing has to do with the nodeType. It should be "4" in order to read the html format (http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html#ID-667469212).
How do I get it to be 4? Im dont know much of this.
Here is the code:
FXMLComboBoxClass.prototype.$addXMLItem = function(xmlNode)
{
this.XMLFile = xmlNode;
trace(xmlNode.nodeType);
//myXML.firstchild.childNodes.nodeValue
var items = xmlNode.firstChild.childNodes;
var itemsLength = items.length - 1;
// clear existent data
this.removeAll();
// populate combo
for(var i=0; i<=itemsLength; i++){
var label = items[i].childNodes[0].firstChild.nodeValue;
var data = items[i].childNodes[1].firstChild.nodeValue;
this.addItem(label, data);
I already put the CDATA thing you told me in the xml file, but about the "nodeValue" deal you mentioned, how do I go about it?
Thanks
btw, this would seal off a month and a half of hard work. Ive learned a lot too!
enrique550
08-27-2004, 06:59 PM
nevermind me!
you're absolutely right. Its working.
haleluyah!!
JEBoothjr
08-27-2004, 09:21 PM
Glad you got it working.
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.