Skip to main content
Handycam
Known Participant
January 16, 2008
Question

Changing XML format to accept HTML tags

  • January 16, 2008
  • 5 replies
  • 380 views
I've inherited an old project from someone. It's a slide show that loads an XML file that contains all the slide info (image, audio, caption, etc.).

The problem is that the image captions now need to contain HTML formatting codes (i,b,u) and the way the XML file was structured doesn't allow for this. The developer used attributes for this information, as in:

<image path="99928009_01.jpg" title="Camaro" caption="A hot car makes a comeback" audio="99928009_01.mp3"/>

I'm assuming I need more like

<image path="99928009_01.jpg" title="Camaro" audio="99928009_01.mp3">
<caption><![CDATA[A <b>hot</b> car makes a comeback]></caption>
</image>

Correct?

If so, how can I easily modify the code to now look for the new "caption" child node? The developer currently has:

var imageNode = root.lastChild;
var s=0;
while (imageNode.nodeName != null) {
imageData = new Object;
var str:String = imageNode.attributes.path;
tar = str.split(".");
ttxt = tar[0]+"_thm."+tar[1];
imageData.t = thumbpath+ttxt;
imageData.audio = audiopath+imageNode.attributes.audio;
imageData.path = imagepath+imageNode.attributes.path;
trace(imageData.path);
imageData.title = imageNode.attributes.title;
if (imageData.title==null){
imageData.title="";
}
imageData.caption = imageNode.attributes.caption;
if (imageData.caption==null){
imageData.caption="";
}
imageArray=imageData;
imageNode = imageNode.previousSibling;
s++
}
...more...

I basically understand what he did here, loop through all the lastChild nodes and extract the attributes. But the XML example above makes <caption> the lastchild, so how do I loop and get the attributes from <image> AND the contents of <caption> and keep them associated??

If this was E4X, I'd have no problem but the older method of dealing with XML always puzzled me a bit.

Thanks.


This topic has been closed for replies.

5 replies

Inspiring
January 16, 2008
You're welcome. Yes you need to embed bold and italic versions of the fonts you're using if you have embedded fonts enabled for your textfield. (and bold-italic combined). For the XML the way I posted is also the correct way to access the CDATA node value if you have a correctly referenced imageNode.
Handycam
HandycamAuthor
Known Participant
January 16, 2008
OK, I figured it out. Here's the silly key item:

You must have a dynamic text field with embedded fonts in every font you might use with the html tags!

Who would've thought. I added additional fields to my file (off the stage) with "foo" set to verdana bold, verdana italic, and verdana bold italic and embedded Basic Latin. Now it works.

Thanks for your help.
Inspiring
January 16, 2008
Is that a real example up there.?

It looks like your CDATA is not correctly closed

<caption><![CDATA[A <b>hot</b> car makes a comeback]></caption>

should be
<caption><![CDATA[A <b>hot</b> car makes a comeback]]></caption>
Inspiring
January 16, 2008
For the html tags...

try

imageData.caption = imageNode.firstChild.firstChild.nodeValue;
Handycam
HandycamAuthor
Known Participant
January 16, 2008
Thanks. I tried that, but the text field then completely omits the word being bolded.
Handycam
HandycamAuthor
Known Participant
January 16, 2008
Never mind, I've gotten it to work by changing

imageData.caption = imageNode.attributes.caption;
if (imageData.caption==null){
imageData.caption="";
}

to

imageData.caption = imageNode.firstChild.firstChild;
if (imageData.caption==null){
imageData.caption="";
}

Still trying to get the html tags to work though.