View Full Version : html tags in xml
worfoual
November 25th, 2004, 07:31 AM
I want to use html tags in a xml file. I've read almost everything I could find about it but it still doesn't work (for me).
xml file:
<?xml version="1.0" encoding="iso-8859-1"?>
<news>
<newsNode newsTitle="Title 1" newsText="This is the text of the first news. <B>Bla bla bla</B> <a href="http://www.whatever.com">click hier</a>. Bla bla bla"></newsNode>
<newsNode newsTitle="Title 2" newsText="This is the text of the second news. <B>I want this bold</B> <a href="http://www.whatever.com">this has to be a link</a>. Bla bla bla"></newsNode>
</news>
Actionscript in Flash:
news_xml = new XML();
news_xml.onLoad = startnewshow;
news_xml.load("news.xml" <http://www.were-here.com/forum/smilies/wink.gif> ;
news_xml.ignoreWhite = true;
//
// Show the first news and intialize variables
function startnewshow(success) {
if (success == true) {
rootNode = news_xml.firstChild;
totalnews = rootNode.childNodes.length;
firstnewsNode = rootNode.firstChild;
currentnewsNode = firstnewsNode;
currentIndex = 1;
updatenews(firstnewsNode);
}
}
//
// Updates the current news with new image and text
function updatenews(newnewsNode) {
newsTitle = newnewsNode.attributes.newsTitle;
newsText = newnewsNode.attributes.newsText;
targetClip.loadMovie(newsTitle);
}
//
// Event handler for 'Next news' button
next_btn.onRelease = function() {
nextnewsNode = currentnewsNode.nextSibling;
if (nextnewsNode == null) {
break;
} else {
currentIndex++;
updatenews(nextnewsNode);
currentnewsNode = nextnewsNode;
}
};
//
// Event handler for 'Previous news' button
back_btn.onRelease = function() {
previousnewsNode = currentnewsNode.previousSibling;
if (previousnewsNode == null) {
break;
} else {
currentIndex--;
currentnewsNode = previousnewsNode;
updatenews(previousnewsNode);
}
};
I've try many things, but I can't get it working.
Can someone help me with this.
worfoual
RvGaTe
November 25th, 2004, 08:18 AM
use it as an CDATA...
here's an example...
http://proto4.thinkquest.nl/~lld287/xml/tekst.xml
worfoual
November 25th, 2004, 08:47 AM
I've try this so many times. But it doesn't work. I try this way:
<?xml version="1.0" encoding="iso-8859-1"?>
<news>
<newsNode newsTitle="Title 1" newsText="![CDATA[This is the text of the first news. <B>Bla bla bla</B> <a href="http://www.whatever.com">click hier</a>. Bla bla bla]]"></newsNode>
<newsNode newsTitle="Title 2" newsText="This is the text of the second news. <B>I want this bold</B> <a href="http://www.whatever.com">this has to be a link</a>. Bla bla bla"></newsNode>
</news> what's wrong?
RvGaTe
November 25th, 2004, 08:50 AM
i cant be used as an attribute
look at the example
worfoual
November 25th, 2004, 02:47 PM
OK, but now I've try this way (without attribut)
<?xml version="1.0" encoding="iso-8859-1"?>
<news>
<newsTitle>
<![CDATA[
<a href="http://www.worfoual.com">Dit project biedt</a> nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
]]>
</newsTitle>
<newsTitle>
tweede nieuws nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
</newsTitle>
</news>
And what I get is (for the first news)
<a href="http://www.worfoual.com">Dit project biedt</a> nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
It doesn't recognice the tag, it just show it as text.
Do you have any idea??
λ
November 25th, 2004, 03:18 PM
Are you using the .htmlText attribute in Flash instead of the .text attribute ? :)
worfoual
November 26th, 2004, 04:11 AM
In Flash I have a Dynamic text field (Var= newsText), Render text as HTML is active and the actionscript is:
news_xml = new XML();
news_xml.onLoad = startnewshow;
news_xml.load("news.xml");
news_xml.ignoreWhite = true;
//
// Show the first news and intialize variables
function startnewshow(success) {
if (success == true) {
rootNode = news_xml.firstChild;
totalnews = rootNode.childNodes.length;
firstnewsNode = rootNode.firstChild;
currentnewsNode = firstnewsNode;
currentIndex = 1;
updatenews(firstnewsNode);
}
}
//
// Updates the current news with new image and text
function updatenews(newnewsNode) {
//newsTitle = newnewsNode.attributes.newsTitle;
newsText = newnewsNode;
targetClip.loadMovie(newsTitle);
}
//
// Event handler for 'Next news' button
next_btn.onRelease = function() {
nextnewsNode = currentnewsNode.nextSibling;
if (nextnewsNode == null) {
break;
} else {
currentIndex++;
updatenews(nextnewsNode);
currentnewsNode = nextnewsNode;
}
};
//
// Event handler for 'Previous news' button
back_btn.onRelease = function() {
previousnewsNode = currentnewsNode.previousSibling;
if (previousnewsNode == null) {
break;
} else {
currentIndex--;
currentnewsNode = previousnewsNode;
updatenews(previousnewsNode);
}
};
And the xml is:
<?xml version="1.0" encoding="iso-8859-1"?>
<news>
<newsNode>
<![CDATA[
<a href="http://www.worfoual.com">Dit project biedt</a> nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
]]>
</newsNode>
<newsNode>
tweede nieuws nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
</newsNode>
</news>
Can you see what's wrong.
RvGaTe
November 26th, 2004, 09:09 AM
try not using the var, instead, use an instance reference...
_root.myTextField.htmlText = your_xml_data
worfoual
November 26th, 2004, 09:25 AM
First I want thank you for your help. But I don't know what you mean with:
use an instance reference...
RvGaTe
November 26th, 2004, 09:56 AM
select the textfield, and look in your properties, there should be a field where you can put your instance name in...
use that instance name to refer to when coding... you can apply text to that field, using his instance name...
so you get t use:
path_to_textfield.your_instance_name.htmlText = your_xml_data;
worfoual
November 26th, 2004, 10:49 AM
Done, but same problem. Can I mail you the Flash and the xml? May be you can beter see what the problem is.
RvGaTe
November 26th, 2004, 10:54 AM
sure, contacting me on msn is alright to...
ill send you pm with adress...
RvGaTe
November 26th, 2004, 11:57 AM
got it:
in your UpdateNews function:
you have
_root.newsText.htmlText = newnewsNode
newnewsNode returns:
<newsNode>
<a href="http://www.worfoual.com">Dit project biedt</a> nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl. nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl. nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
</newsNode>
but you need the content of newsNode, wich can be accesed with newnewsNode.firstChild
that returns:
<a href="http://www.worfoual.com">Dit project biedt</a> nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl. nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl. nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
and finaly, to get rid of the strance stuff like @amp; etc, use newnewsNode.firstChild.nodeValue;
that returns:
<a href="http://www.worfoual.com">Dit project biedt</a> nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl. nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl. nieuwe leden van de BNO (Beroepsorganisatie Nederlandse Ontwerpers) de mogelijkheid om ansichtkaarten te laten produceren bij Spinhex & Industrie. Voor spelregels zie www.bno.nl
now you can easily assign this to your .htmlText, and it works perfectly, so your final code for your function would be:
function updatenews(newnewsNode) {
_root.newsText.htmlText = newnewsNode.firstChild.nodeValue;
}
there you have it, a working news system :)
λ
November 26th, 2004, 12:45 PM
Sidenote: Please use the AS ([ as][ /as] tags without the spaces) - they make code much more readable :)
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.