-
[RESOLVED] CDATA and formating XML text
Last edited by AVaughn; 08-19-2010 at 09:01 PM.
-
<date><![CDATA[<b>Primary:</b> Aug. 19th]]></date>
while (2+2 == 4) {
drink ("bourbon");
}
gotoAndStop("bed");
-
UPDATE: I have set up dynamic text fields to be rendered as HTML and have embed the font. This all works fine the text node content gets imported and displayed fine, however I need to bold some of the text. For example the word "primary" in the first node should display as bold. I have tried the following with no success. The dynamic text fields are in a movieclip on the main timeline called "mc_allstates".
The first node only one I have added CDATA to for testing <date> displays like this:
<b>Primary:</b> Aug. 19th
Not sure what I am missing?
XML File
<?xml version="1.0" encoding="UTF-8"?>
<data>
<title name="Oregon">
<date><![CDATA[<b>Primary:</b> Aug. 19th]]></date>
<incumbent>398</incumbent>
<challenger>12 *</challenger>
<O8result>10.6%</O8result>
<partyreg>11.2%</partyreg>
<pop55>4.9%</pop55>
<overview>$4.2 bil.</overview>
<keyissues>29% ***</keyissues>
<wildcard>-8.81%</wildcard>
<funfact>47 **</funfact>
<hold>$570.30 mil.</hold>
</title>
</data>
XML Load:
myXML.onLoad = function(succes){
if(succes){
trace (state_no);
var root = this.firstChild;
nodes = root.childNodes;
mc_allstates.Title_txt.htmlText = nodes[state_no].attributes.name;
subnodes = nodes[state_no].childNodes;
mc_allstates.date_txt.htmlText= subnodes[0].firstChild.toString();
mc_allstates.incumbent_txt.htmlText= subnodes[1].firstChild.toString();
mc_allstates.challenger_txt.htmlText= subnodes[2].firstChild.toString();
mc_allstates.O8result_txt.htmlText= subnodes[3].firstChild.toString();
mc_allstates.partyreg_txt.htmlText= subnodes[4].firstChild.toString();
mc_allstates.pop55_txt.htmlText= subnodes[5].firstChild.toString();
mc_allstates.overview_txt.htmlText= subnodes[6].firstChild.toString();
mc_allstates.keyissues_txt.htmlText= subnodes[7].firstChild.toString();
mc_allstates.wildcard_txt.htmlText= subnodes[8].firstChild.toString();
mc_allstates.funfact_txt.htmlText= subnodes[9].firstChild.toString();
mc_allstates.hold_txt.htmlText= subnodes[10].firstChild.toString();
} else trace("Error loading XML document")
Last edited by AVaughn; 08-19-2010 at 08:30 PM.
-
I believe the issue is that you are not embedding regular and bold style fonts.
One way to solve this is to enter text into the dynamic text field and select one of the characters and bold it. Leaving another character as a regular style.
*Make sure the text field is selected to Render as HTML.
-
I do have two characters in the dynamic fields one bold one not and I have embeded them even though they are arial. I dont think that is the problem it's not parsing the CDATA as html. I not only selected HTML in properties I also code it in the load in the beginning. I am stumped. It can't be a scope problem because it parses the text fine just doesn't format it, displays code instead.
-
Instead of assigning the value like:
Code:
mc_allstates.date_txt.htmlText= subnodes[0].firstChild.toString();
try this instead
Code:
mc_allstates.date_txt.htmlText = subnodes[0].firstChild.nodeValue;
-
Thanks FP I would never have tried that its so logical. If I can help you anytime dont hesitate to ask I am also pretty good illustrator.
-
XML rendered as hrml
I've designed a flash app for teaching German.
Basically my application displays images with associated text.
My xml looks like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow>
<slide url = "image1.jpg" sound = "sound1.mp3" text = "Wir sind Ski gefahren" english = "We went skiing"/>
<slide url = "image2.jpg" sound = "sound2.mp3" text = "Wir sind Rad gefahren" english = "We went cycling"/>
</slideshow>
Obviously my real xml file is much longer than this!
I want to render 'text' as html, so that I can assign a line break in a dynamic text box,
for example:
Wir sind
Ski gefahren
We went
skiing
My XML structure is different to yours, I think.
How do I insert the CDATA bit?
-
CDATA won't work inside an attribute. The proper way is to use it inside the node value. I rewrote your sample code in a way that will allow for this.
Code:
<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow>
<slide>
<url>image1.jpg</url>
<sound>sound1.mp3</sound>
<text><![CDATA[Wir sind<br/>Ski gefahren]]></text>
<english>We went skiing</english>
</slide>
<slide>
<url>image2.jpg</url>
<sound>sound2.mp3</sound>
<text><![CDATA[Wir sind<br/>Rad gefahren]]></text>
<english>We went cycling</english>
</slide>
</slideshow>
-
Thanks!
I'll give that a try!
-
Thanks for your suggestion, but I can't get it to work.
The text displays in my dynamic text box as, for example:
Wir sind <br/> Ski gefahren
I've tried setting the text box to render the text as html, and that didn't work either, in fact when I did, no text appeared.
my code is:
textBox_txt.htmlText = textArray[currentElement]
(text Array is an array containing all the German text. When I do a trace statement on textArray, the German sentences all show up, but, again, with the <br/> tag in there.
Also, when I pasted your code into Dreamweaver, the text before the <br/> tag was the same colour as the xml tags (in my case blue) whereas the text after the <br/> tag was black. Does this help?
-
Does it work fine if you remove <br/> from the XML?
It could also be an font embed issue. Select the text box and under the PROPERTIES section click "Character Embedding" and select the character sets you need to to embed. If that doesn't work, please include more of your code so I can help trouble shoot.
FYI: Dreamweaver's color scheme is not the best for XML documents.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|