To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash 8

Reply
 
Thread Tools Search this Thread Rate Thread Display Modes
Old 05-07-2007, 06:20 PM   #1
dissidenz
Junior Member
 
Join Date: May 2007
Posts: 6
Display only some XML nodes

Hi,
Apologies if this has been answered before, but I've searched the forum and can't find an answer that seems to work. I'm pretty new to displaying xml content in Flash, so I may be missing some pretty basic stuff.

I'm reading a remote xml file and using an external css file to style it; all of that is working fine. Unfortunately, the xml data is used to create hotspots on a map as well as display the text on a text page, so there are nodes that are only used for the map (i.e., latitude and longitude) that I don't want to display on the text page. But I can't figure out how to get tell the actionscript that loads the xml to ignore some of the nodes.

It has occurred to me that the xml I'm calling may not be formatted correctly for this, but I don't have access to that file, so I have to make do with it as is.

Anyway, here's the code I'm using to display the xml as text:
(i've replaced the url to the xml because it's my client's site)

//init TextArea component
myText.html = true;
myText.wordWrap = true;
myText.multiline = true;
myText.label.condenseWhite = false;
contentStyle = new TextField.StyleSheet();
contentStyle.load("ksm.css");
myText.styleSheet = contentStyle;
//load in XML
ksmContent = new XML();
ksmContent.ignoreWhite = false;
ksmContent.load("http://www.site.com/name.xml");
ksmContent.onLoad = function(success) {
if (success) {
myText.text = ksmContent;
}
};

and for completeness sake, here's a sample of the xml in question:

<events>
<event>
<id>24</id>
<timestamp>1156996800</timestamp>
<latitude>-29.85</latitude>
<longitude>31.0167</longitude>
<title><![CDATA[Rise of Super Tuberculosis]]></title>
<image/>
<contenttext><![CDATA[KWAZULU-NATAL, South Africa, Aug. 31, 2006 - A new strain of extensively drug resistant tuberculosis (XDR-TB) has been reported in KwaZulu-Natal. This &quot;super tuberculosis&quot; is resistant to all the first and second line TB drugs, making it virtually untreatable. Additionally, this strain seems to kill particularly rapidly; many patients dying within a month of diagnosis.<br /><br />XDR-TB develops when patients do not take antibiotics properly and can be spread through sneezing and coughing. According to a survey by the CDC and WHO, approximately 2 percent of all TB isolates examined between 2000 and 2004 were XDR-TB.]]></contenttext>
</event>
<event>

The only nodes I want to display are <title> and <contenttext>.

Oh, and while we're at it, the html tags in the <contenttext> node aren't working properly...

If anyone can help... tia!!
dissidenz is offline   Reply With Quote
Old 05-07-2007, 08:31 PM   #2
EvolveDesigns
Ryan Thomson
 
EvolveDesigns's Avatar
 
Join Date: Oct 2001
Location: British Columbia
Posts: 3,332
look over the flash help files for the various xml names, then start playing around with creating and tracing a variable path like so:

if (success) {
myText.text = ksmContent;
thisNode = ksmContent.firstChild.firstChild;
trace(thisNode);

what i have may not work, finding paths in xml is tricky for me and i find the best method is trial and error in the early stages. If i had to guess i would say that this would trace everything between <id> and </contenttext> so if you added another firstChild it would go one level deeper into your xml. Look up:

firstChild
childNodes
nodeValue
attribute

and you should be good to go!

good luck
}
__________________
Evolve Designs Interactive Media
the natural selection
EvolveDesigns is offline   Reply With Quote
Old 05-07-2007, 08:52 PM   #3
cancerinform
Mod
 
cancerinform's Avatar
 
Join Date: Mar 2002
Location: press the picture...
Posts: 12,312
Set ksmContent.ignoreWhite = false; to true. Otherwise all the white space is counted as nodes.
__________________

- The right of the People to create Flash movies shall not be infringed. -
| www.Flashscript.biz | Help a little girl, Ana, who has cancer. | Flashscript Biz Classes/Components | The new Event design pattern | Clothing for Haiti |
cancerinform is offline   Reply With Quote
Old 05-08-2007, 05:13 PM   #4
dissidenz
Junior Member
 
Join Date: May 2007
Posts: 6
Thanks, folk, that's been very helpful... at least some progress is being made. Still in the woods, though... using the two comments above, i've able to get a list of the <id> tags in my xml (it outputs a list of all of them, starting with the "24" you see in the xml i posted, and going all the way up to the "45" in the full xml file). But if I add more firstChild's into the string, i only get a list of "null"s or "undefined"s, not the other tags' contents, like "timestamp", etc.

And even assuming I'm able to get to the point of being able to identify all the nodes through ActionScript, that still doesn't tell me how to do what I really need, which is how to hide some of them in the output (and i did read through the Flash help on all the subjects listed above.) I thought I'd be able to use removeNode for that, since I can now identify the <id> tag at least, but that doesn't seem to be working.. no errors, but the text still displays...

Anyone have any ideas?

thx.
dissidenz is offline   Reply With Quote
Old 05-08-2007, 07:31 PM   #5
EvolveDesigns
Ryan Thomson
 
EvolveDesigns's Avatar
 
Join Date: Oct 2001
Location: British Columbia
Posts: 3,332
well basically xml is actually an array so if you can trace out everything between <events> and </events> by tracing thisNode (meaning ksmContent.firstChild.firstChild from my example) then if you were to trace thisNode[1] it would trace the first element in the array of nodes meaning <id>24</id> and if you traced thisNode[2] it would show <timestamp>1156996800</timestamp> and so on. It's a bit tricky figuring out the paths, but once you get one the rest are a cakewalk..

If i get a chance later tonight I'll send you a working script for bringing up your nodes (to celebrate my 1000th post! wootwoot)
__________________
Evolve Designs Interactive Media
the natural selection

Last edited by EvolveDesigns; 05-08-2007 at 07:33 PM.
EvolveDesigns is offline   Reply With Quote
Old 05-08-2007, 08:33 PM   #6
dissidenz
Junior Member
 
Join Date: May 2007
Posts: 6
awesome! now we're getting somewhere... i actually had to change the code slightly to
thisNode = ksmContent.firstChild.firstChild.childNodes;
to get it to trace out the nodes properly, but now i have a list of all the nodes in the array, and i've commented them so i know which are which.

i still can't figure out how to use that knowledge to prevent some nodes from displaying , though... (sorry for my denseness); and i also can't figure out how to get the html codes in the text blocks of the <contenttext> nodes to display properly...

any clue?

thanks for all your help!
dissidenz is offline   Reply With Quote
Old 05-08-2007, 08:41 PM   #7
cancerinform
Mod
 
cancerinform's Avatar
 
Join Date: Mar 2002
Location: press the picture...
Posts: 12,312
Instead of firstChild.firstChild try firstChild.nextSibling
It's a big family
__________________

- The right of the People to create Flash movies shall not be infringed. -
| www.Flashscript.biz | Help a little girl, Ana, who has cancer. | Flashscript Biz Classes/Components | The new Event design pattern | Clothing for Haiti |
cancerinform is offline   Reply With Quote
Old 05-08-2007, 08:58 PM   #8
dissidenz
Junior Member
 
Join Date: May 2007
Posts: 6
ahhh, never mind on the first part of that question... I just realized I can do that with the "display" property in the external css file I'm using.
dissidenz is offline   Reply With Quote
Old 05-08-2007, 09:31 PM   #9
dissidenz
Junior Member
 
Join Date: May 2007
Posts: 6
oops, wrong again... although setting "display" to "none" in the css file successfully hides the tags in question, it leaves space for them, even though the css spec says it shouldn't... so i'm ending up with big white spaces between the paragraphs of text. so i'm back to hoping this is something that can be controlled by Flash...
dissidenz is offline   Reply With Quote
Old 05-09-2007, 01:00 AM   #10
EvolveDesigns
Ryan Thomson
 
EvolveDesigns's Avatar
 
Join Date: Oct 2001
Location: British Columbia
Posts: 3,332
thes reason you can see the tags is because you have to define the textfield as html when loading stuff so

myText.text = ksmContent;

would become

myText.htmlText = ksmContent;
__________________
Evolve Designs Interactive Media
the natural selection
EvolveDesigns is offline   Reply With Quote
Old 05-09-2007, 01:12 AM   #11
EvolveDesigns
Ryan Thomson
 
EvolveDesigns's Avatar
 
Join Date: Oct 2001
Location: British Columbia
Posts: 3,332
Ok I ended up making a little code that reads the newest digg from digg.com and traces it out, I think it may help you understand how this works


Code:
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("http://digg.com/rss/index.xml");

function loadXML(success) {
	if (success) {
		parseXML();
	}
	else {
		trace("Oh noes! Digg is dead!");
	}
}

function parseXML(){
	story = xmlData.firstChild.firstChild.childNodes;
	titles = story[4].childNodes[0].childNodes;
	link = story[4].childNodes[1].childNodes;
	description = story[4].childNodes[2].childNodes;
	pubDate = story[4].childNodes[3].childNodes;
	digCount = story[4].childNodes[5].childNodes;
	category = story[4].childNodes[7].childNodes;
	commentsCount = story[4].childNodes[8].childNodes;
	newestDigg = "<b><a href='" + link + "'>" + titles + "</a></b>\r\r" + description + "\r\r" + pubDate + " :: " + "digg count:" + digCount + "\rcategory: " + category + " :: " + "comments count: " + commentsCount;
	trace(newestDigg);
	digg_txt.htmlText = newestDigg;
}
I found the path in the xml to all the <items></items> which are the containers for each of the stories, then named that 'story' in the above code. I then dug into each story to separate all the various elements, note the number beside the first childNodes, each one represents one of the elements in the story array. If i wanted to view a different story all together i would change all the 4's beside story to say 7 then it would trace out the the info from a different <item> node.

I think if you check out the xml im calling on digg beside the above code you should get the idea. (or jsut be totally confused by all this information lol)

good luck!
__________________
Evolve Designs Interactive Media
the natural selection
EvolveDesigns is offline   Reply With Quote
Old 05-09-2007, 02:14 PM   #12
dissidenz
Junior Member
 
Join Date: May 2007
Posts: 6
okay, better all the time! (can't thank you enough for all this help).. the htmlText thing still isn't working though; on both your script and mine, if I change the .text to .htmlText the textarea stays blank. I have it set to "html=true" in the component parameters, but it will only display the output if I have the content set to .text.

Also, this is working great for displaying a title and text , but the xml I'm pulling from has a whole series of titles and text blocks, and I won't always know how many of them there are. Is there a way to construct a "for" loop or something to address that?

thanks again...
dissidenz is offline   Reply With Quote
Old 05-09-2007, 03:39 PM   #13
cancerinform
Mod
 
cancerinform's Avatar
 
Join Date: Mar 2002
Location: press the picture...
Posts: 12,312
For the textarea use only .text. Only for textFields you need to use htmlText.
__________________

- The right of the People to create Flash movies shall not be infringed. -
| www.Flashscript.biz | Help a little girl, Ana, who has cancer. | Flashscript Biz Classes/Components | The new Event design pattern | Clothing for Haiti |
cancerinform is offline   Reply With Quote
Old 05-09-2007, 04:33 PM   #14
EvolveDesigns
Ryan Thomson
 
EvolveDesigns's Avatar
 
Join Date: Oct 2001
Location: British Columbia
Posts: 3,332
o right, it's a text area oops

(with mine, it works you just have to set the textfield to html in the properties bar
__________________
Evolve Designs Interactive Media
the natural selection
EvolveDesigns is offline   Reply With Quote
Old 05-09-2007, 04:40 PM   #15
EvolveDesigns
Ryan Thomson
 
EvolveDesigns's Avatar
 
Join Date: Oct 2001
Location: British Columbia
Posts: 3,332
the for loop would look something like this:

for(i=0;i<story.length;i++){
titles = story[i].childNodes[0].childNodes;
trace(titles);
}

if you added this to the bottom of my parseXML function it would trace out every title for all the new posts at digg.com. If you replaced the trace with an array it would load each title into the array where you could have full control dynamically. hope that helps
__________________
Evolve Designs Interactive Media
the natural selection
EvolveDesigns is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash 8

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:38 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.