Formatting XML Text - Need Help

Is it possible to add bold or italics to parts of the text in my XML file? I have my textfield set as “htmlText”, and I’ve turned on “render text as html”. I can’t get it to work. I did find one forum posting on this here, but it uses a different setup. Other Post

XML File:


  <gallery>
  <image type="photo" 
  main="images/01.jpg" 
  thmb="images/01_sm.jpg" 
  title="Title Text" 
  desc="Description goes here." />
  </gallery>

I’ve tried this, but it isn’t working.


   <gallery>
   <image type="photo" 
  main="images/01.jpg" 
  thmb="images/01_sm.jpg" 
  title="Title Text" 
  desc="Description goes [color=Red]<b>[/color]here[color=Red]<b>[/color]." />
   </gallery>

Using this breaks the XML. I am assuming it is because it is reading the brakets, and I’ve tried using / in front of the brakets or ‘<b>’ around the HTML tag.

Anyone know how to do this?

you have to use CDATA tags in your xml nodes so that the html tags arent parsed as xml. You will have to restructure your xml to be more ‘robust’ (ie, you can’t use CDATA in tag attributes, only in nodes.)
so u will havta change desc= “desc” to <desc><![CDATA[ description goes <b>here</b> ]]></desc>
Also, when you do target the nodes in AS, remeber to add .nodeValue to the end so that the html formatting within the node is accessed. (Scotty and I spent days figuring this out when I had the same problem, haha… )
hope that helps! if not, post up your xml and AS and we’ll figure it out.

Thanks for the rely dr.ew!

The thing I’m struggling with is that my current actionscript counts the number of images or occurances of <image>, and creates thumbnail buttons from each one. It also changes the title and description when you click on an image.

So I understand what you are suggesting, but not sure how to change my system since what I’m currently doing is so different.

My AS:

myPhoto = new XML();
 myPhoto.ignoreWhite = true;
 myPhoto.onLoad = function(success) {
 	numimages = this.firstChild.childNodes.length;
 	spacing = 62;
 	for (i=0; i<numimages; i++) {
 		picHolder = this.firstChild.childNodes*;
 		thumbHolder = thumbnails.createEmptyMovieClip("thumbnail"+i, i);
 		thumbHolder.n = i;
 		thumbHolder._x = i*spacing;
 		thumbLoader = thumbholder.createEmptyMovieClip("thumbnail_image", 0);
 		thumbLoader.loadMovie(picHolder.attributes.thmb);
 		thumbHolder.type = picHolder.attributes.type;
 		thumbHolder.main = picHolder.attributes.main;
 		thumbHolder.title = picHolder.attributes.title;
 		thumbHolder.desc = picHolder.attributes.desc;
 		thumbHolder.onRelease = function() {
 			closeoutOver(this.n);
 			loader.box.loadMovie(this.main);
 			over["over"+this.n].gotoAndStop(3);
 			desc.htmlText = this.desc;
 			title.text = this.title;
 		};
 
 		thumbHolder.onRollover = function() {
 		if (over["over"+this.n]._currentframe == 3) {
 			over["over"+this.n].stop();
 		}else{	
 			type.text = this.type;
 			over["over"+this.n].gotoAndStop(2);
 			over["over"+this.n].z.type.text = this.type;
 		}
 		};
 
 		thumbHolder.onRollout = function() {
 		if (over["over"+this.n]._currentframe == 3) {
 			over["over"+this.n].stop();
 		}else{	
 			over["over"+this.n].gotoAndStop(1);
 		}
 		};

My XML:

  <gallery>
  <image type="photo" main="images/Image1.jpg" thmb="images/Image1_sm.jpg" 
  title="Image One Title" desc="Image One Here" />
  <image type="photo" main="images/Image2.jpg" thmb="images/Image2_sm.jpg" 
   title="Image Two Title" desc="Image Two Here" />
  </gallery>

Ok, well here is what your xml should look like. (for things that you don’t need any html tags for, and therefore dont need CDATA tags for, you could still use attributes. I just changed it all wholesale so u could see the difference.):


<?xml version="1.0" encoding="utf-8"?>
<gallery>
	<image>
		<type>photo</type>
		<main>images/image1.jpg</main>
		<thmb>images/imagethb.jpg</thmb>
		<title>title</title>
		<desc><![CDATA[<b><u>this text is bold and underline in htmlText</u></b>]]</desc>
	</image>
	<image>
		<type>photo</type>
		<main>images/image1.jpg</main>
		<thmb>images/imagethb.jpg</thmb>
		<title>title</title>
		<desc><![CDATA[<b><u>this text is bold and underline in htmlText</u></b>]]</desc>
	</image>
</gallery>

Now, as far as referencing things, you should look through Senoculars amazing XML tutorials. That way you’ll really be able to dig in and understand.
Anyway, here is how the main things will change.

picHolder = this.firstChild.childNodes*; //this points to the current <image> tag in the for loop, so doesnt need to change.

thumbLoader.loadMovie(picHolder.childNodes[2].nodeValue); //accesses thumbnails

thumbHolder.type = picHolder.childNodes[0].nodeValue;
thumbHolder.main = picHolder.childNodes[1].nodeValue;
thumbHolder.title = picHolder.childNodes[3].nodeValue;
thumbHolder.desc = picHolder.childNodes[4].nodeValue;

I think that should path to the proper places in the xml, but I havent checked it in flash…Use your trace function and you’ll figure it out.
Hope that helps=]