View Full Version : FMX - external xml broken by html tags
borispc
June 28th, 2004, 12:58 PM
Hello! :trout:
I am having a little trouble figuring out how to solve this issue.
I am loading an external xml into flash. The parsing works perfectly except for the fact that I can't display the text between html tags.
Flash interprets the html tag as an xml tag so it brakes the text chain. It just doesn't display the text after that in that node.
It didn't work with textField.html properties set to true.
Does anyone know how to make flash skip the html tags in that xml formatted text?
thanks!
zao
June 28th, 2004, 01:50 PM
Make sure for your textField, that you check use html, also make your instance of the textfield like say its newsText, make sure you use
newsText.htmlText = xmlDoc;
and not just newsText.text = xmlDoc;
borispc
June 28th, 2004, 02:45 PM
That didn't work either.
Trying to trace the problem I think that the problem actually lies in the parsing of the xml in flash. I'm still working on it but I think that flash creates a new subnode because considers that something like <i>the fields of Colorado</i> is a new node.
Here's what that piece of code looks like:
for (var j = 0; j<propertyNode.childNodes.length; j++) {
itemNode = propertyNode.childNodes[j];
temp = itemNode.childNodes[0];
tempArray.push(temp);
}
The problem is that those html tags (italic, bold, etc) are causing itemNode.chilNodes[1], itemNode.childnodes[2],...that get lost because right now I'm only including childNodes[0] which are the only ones I would need if this wasn't happening.
I'm not sure how to add those other childNodes correctly to tempArray.
Any ideas on how to fix this?
Hope my explanation is not too confusing.
thanks.
skinnyot
June 29th, 2004, 06:08 AM
this isn't a clever flash solution i'm afraid, but if you have the option of changing the format of the xml doc being parsed, enclose all html in the xml doc in CDATA tags, and flash will ignore everything inside them when parsing.
borispc
June 29th, 2004, 06:11 AM
this isn't a clever flash solution i'm afraid, but if you have the option of changing the format of the xml doc being parsed, enclose all html in the xml doc in CDATA tags, and flash will ignore everything inside them when parsing.
Forget my ignorance. What are CDATA tags? can you give an example.
I am not in charge of generating the xml, it comes from and ASP programmed by someone else.
thanks.
skinnyot
June 29th, 2004, 07:18 AM
I use xml docs in the following format :
<mainxml>
<sub>
<webtext><![CDATA[I am text that is <B><I>ignored</I></B> by flash xml parser and stored as the <B>node value</B>.]]></webtext>
</sub>
</mainxml>
when you load it in, you can show ..
loaded_xml.firstChild.firstChild.childNodes[n].firstChild.nodeValue;
in a text field with the 'render as html' setting.
borispc
June 29th, 2004, 07:59 AM
I must be missing something because when I use CDATA tags in my xml file, even if my text field is set to render html text, it displays the text with the tags. It doesn't interpret the html tags. Even if I pass the text as htmlText to the text field.
The part about flash ignoring the html tags inside a CDATA worked though.
:hugegrin:
skinnyot
June 29th, 2004, 09:11 AM
hmm, ok. i messed about a bit and got what you're talking about to happen. And here's what made the difference.
In my version that works: i have a mc instance named 'box' on the stage with a text box inside it. The text box is set to 'render as html', has no instance name, and has a variable name of 'txt'. I pass the node value from the xml to the variable directly and it works, not showing any html tags. i.e
box.txt = xmlnodevalue;
When i removed the variable name and instead made the instance name of the text box 'txt' then
box.txt.text = xmlnodevalue;
made the html tags appear in the text box.
However, with the same text box set up ...
box.txt.htmlText = xmlnodevalue;
worked, in that it didn't show the html tags, just the nice formatting:)
hope this helps,
Skinny.
borispc
June 29th, 2004, 02:25 PM
Here's what happens:
1) if xml is...
<data>
<property><name><i>john</i></name></property>
<property><name><b>patrick</b></name></property>
</data>
The text is loaded fine with the right formatting. Things get messed up once we have words with and without html tags in the same xml node:
2) if xml is...
<data>
<property><name><i>john</i></name></property>
<property><name><b>patrick</b> jones</name></property>
</data>
Then, "jones" is lost, the rest still respects the formatting.
3) If we try to introduce CDATA tags:
<data>
<property><name><i>john</i></name></property>
<property><name><![CDATA[<b>patrick</b>jones]]></name></property>
</data>
Then, the text field displays...
john (in italics) <b>patrick</b> jones
And output window tracing that node shows...
<name><b>patrick</b>jones</name>
And that is passing the value like this:
myMovieclip.mytextField.htmlText=xmlNode;
myMovieclip.myTextFieldVariable=xmlNode; (shows the same as above);
myMoveclip.myTextFieldVariable.htmlText=xmlNode;(d oes not show anything because htmlText can only be applied to text fields (using the instance name) and not text field variables)
Thanks!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.