Skip to main content
Participating Frequently
July 9, 2013
Answered

</span> causing extra space in htmlText

  • July 9, 2013
  • 1 reply
  • 1664 views

I'm loading text from an xml file that has some CDATA as well as <span class> in it.  The xml file would look like this:

<?xml version="1.0"? encoding="utf-8"?>
<allPages id="Execution Management - Replanner" version="1.6" template="djc2_1_5" audioType="MP3" videoType="WMV">
<page id="8">
<narration>
<![CDATA[hello<step>Step 1 text <span class = 'mycolor'>with some text followed by a comma</span>, followed by some more text</step>]]>
</narration>
</page>
</allPages>

The problem I'm getting is when i put the CDATA text into a textfield, an extra space is being added after the </span. ie. "with some text followed by a comma ,".  This space is being added only if there is some kind of punctuation immediately following </span> in the xml document.  I've tried getting rid of it with regular expressions and split().join but nothing has worked.

This topic has been closed for replies.
Correct answer kglad

That example works but i won't be able to just say tf.htmlText = xml.page.narration.text();  The example has only one <step></step> so that works.  I'll need to so something like when a button is clicked, tf.htmlText = xml.page.narration.step[0];, tf.htmlText = xml.page.narration.step[1]; etc. since there's going to be many many steps within the CDATA and they'll need to show individually in the text box.


that makes no difference (except to show that whoever created that xml format using <step> in the cdata instead of step tags in the xml wasn't knowledgeable). 

it also points out that your problem has nothing to do with </span> or the css.  the problem is whatever you're doing to handle the <step> tag is introducing the problem.

anyway, just use:

function f(e:Event):void{

var xml:XML = XML(urlloader.data);

var s:String = xml.page.narration.text();

var a:Array = s.split('</step>').join('').split('<step>');

a.shift();

}

1 reply

kglad
Community Expert
Community Expert
July 9, 2013

what is <step>?

and, more importantly, what are the mycolor attributes that are causing that problem?

Participating Frequently
July 9, 2013

Ultimately, the xml document will have alot of pages (page id="1", "2" etc.) and within the CDATA, there will be several steps.   I just simplified everything in the example.  In Flash, I'm accessing "page 8" and putting the text between <step></step> into an array (stepArray) and when a button is clicked, a textfield gets populated with stepArray[0].  Here, I only have one "step" but there will be a stepArray[1], stepArray[2] etc.  CSS is applied to the textfield so mycolor is setting that specific text to red.

I'm stuck with how the xml is formed since it's generated from some custom application.  The function in flash doing all of this is

function showXML(e:Event):void

{

          XML.ignoreWhitespace = true;

          var xml:XML = new XML(e.target.data);

 

          var stepString = "<allSteps>"+xml.page[8].narration+"</allSteps>";

          var output:XML = new XML(stepString);

 

          for each ( var step:XML in output.step){

           stepArray.push(step);

          }

}

stepTxt.condenseWhite=true;

kglad
Community Expert
Community Expert
July 9, 2013

again, what are the mycolor attributes that are causing that problem?  ie, copy and paste that class.