Skip to main content
Participant
February 26, 2009
Answered

Using XML as plain text in TextFilter

  • February 26, 2009
  • 1 reply
  • 657 views
I have an application with an XML tag:
<mx:XML id="textXML1">
<root><c1>goodbye</c1></root>
</mx:XML>

I then have a string variable which I set equal to that XML:

var t:String = textXML1;

I then set up a TextFlow by the following line of code:

textFlow = TextFilter.importToFlow(t, TextFilter.PLAIN_TEXT_FORMAT);

However, I then do a trace of the text value in the TextFlow:

trace("textFlow's text: " + TextUtil.extractText(textFlow));

The resultant dump is:

textFlow's text: <root>

<c1>goodby
<c1>goodbye


Any ideas?
This topic has been closed for replies.
Correct answer brian_thomas2
I'm not able to reproduce any problems importing XML as plain text. The problem must be in TextUtil.extractText(). I recommend that you pass this on to the Flex team via their bug database.

1 reply

Adobe Employee
February 26, 2009
I think when you assign XML to a String it calls toString on the XML. When XML.toString() is called on complex content that is the expected result. You can traverse the XML and call toString on the simple content (e.g., on c1). If all the text is going to be in a c1 element, you can make an e4x expression that selects all of the c1s and get the text by traversing the list, perhaps something like: "mx:XML...c1". I usually do a bit of trial and error on these types of things, so I can't give you any useful code snippets, but those are a few things you could try. Maybe someone more familiar with e4X than I am could chime in.
Participant
February 26, 2009
Yes, the XML.toString() method is called. This means that t is the result of textXML1.toString(), which, on complex XML, produces a string of the entire XML object, tags and all. If I do a trace on t, the output is:

<root>
<c1>goodbye</c1>
</root>

That is expected. That also means that the value of "t" is no longer XML, just a string that looks like XML.

What is unexpected is the malformed "xml" string produced when it's been handled by the TLF. If you note from my first post, the result of TextUtil.extractText(textFlow) is not the entire "xml" string, but rather a malformed version of it. I'm assuming this is a bug in either TextFilter.importToFlow() or TextUtil.extractText(), but, since there are no exposed variables/properties on the TextFlow's text (if it has such a variable at all), I have no way of knowing where this is breaking down.
brian_thomas2
Adobe Employee
brian_thomas2Correct answer
Adobe Employee
February 26, 2009
I'm not able to reproduce any problems importing XML as plain text. The problem must be in TextUtil.extractText(). I recommend that you pass this on to the Flex team via their bug database.