PDA

Click to See Complete Forum and Search --> : Finding XML Nodes with ActionScript



ejc
07-13-2001, 09:27 AM
I am writing my first Flash/XML solution and I am having trouble using the nodes to find the XML data:

If my firstChild is the xml declaration and the sibling to that (1st xml data node) is "instrument" to find and display the value of "currency" I used this:

if (mainTag.nodeName.toLowerCase() == "instrument") {
segmentList = mainTag.childNodes;
prices_display = "";
for (i=0; i<=segmentList.length; i++) {
// initialize variables to hold xml data we want displayed
currency= "";


// loop through that looking for the data we need
for (j=0; j<=segmentList.length; j++) {
elementTag = segmentList[j];
elementType = elementTag.nodeName.toLowerCase();

if (elementType == "currency") {
textfieldcurrency = elementTag.firstChild.nodeValue;
}
}
}
}

So now I want to find the node value of.. say... "name" that is a child of "market" which is a child of "instrument". And it's proving quite tricky for me. Can anyone offer advice on how to reach those nodes that are further in the xml tree?

Thanks in advance
ejc.


[Edited by ejc on 07-13-2001 at 09:31 AM]

tupps
07-14-2001, 01:02 AM
Would it be possible for you to post a link to your XML.


I find that the easiest way to extract data out of the XML is to have a bunch of nested for loops that go through all the children of the node you want, which to me looks like you just need an extra for loop in your very inner loop.

Thanks

Luke

ejc
07-31-2001, 08:36 AM
Thanks for the reply, if you could take a look at this url for an xml example.

http://www.hemscott.com/emma/flash/testxml.xml

I am having trouble pulling out the info from
- MARKET > NAME
and
- HISTORY > PERIOD >PRICE.

Any help you can offer would be fantastic!

Thanx,
Emma.

tupps
07-31-2001, 09:37 PM
Can you check that link, throughs up an error for me!

Thanks

Luke

ejc
08-03-2001, 07:02 AM
Not sure what the problem is, I can see it fine..?

Try this URL - it contains an image of the xml, that might help???

http://www.hemscott.com/emma/flash/xmlgif.htm

Thanx
Emma.

tupps
08-05-2001, 07:20 AM
OK,

got a handle on what you are trying to do now!

When you are trying to go down the chain I use loops and counters eg to find: Instrument -- Market -- Name

You have already got the childnodes of instrument, so you could use:

for (counterA in segmentList){
if (segmentList[counterA].nodename == "Market") {

for (counterB in segmentList[counterA].childNodes) {
if (segmentList[counterA].childNodes[counterB].nodeName == "Name") {
//Rem Do something here
}
}
}


Does this help?

If you want have a look at:

http://www.tupps.com/flash/latestNewsTutorial.html

Thanks

Luke

ejc
08-06-2001, 06:00 AM
Excellent... it works a treat, thanks a million Luke.

I might have some more for you as I work through this project... hope you don't mind

Cheers,

Emma.

tupps
08-06-2001, 07:14 AM
Not a problem, if you want drop me an email at:

flash@tupps.com

Thanks

Luke