Solved

Retrieving XML Node Values and Node Names using Actionscript

Posted on 2007-11-20
2
981 Views
Last Modified: 2012-05-05
I've got an XML file that I'm retrieving using Flash Remoting. That part is working fine, but in the function that I run once I get the data, I'd like to take the node names and the node values and place them both in an array to use later in the program. I'm having a difficult time retrieving the node value. I've attached a simplified version of my code so you can see what I'm doing and where the problem is occuring.

Thanks for any help - I'm stumped.
function gotConfig(re:ResultEvent) {
   var vConfigXML = re.result;
   var tempconfig_xml:XML = new XML(vConfigXML);
   tempconfig_xml.ignoreWhite = true;
   trace("tempconfig_xml: " + tempconfig_xml);
   //result
   /* <?xml version="1.0" encoding="UTF-8"?>
<config><bkgimage>images/bkg_browsevideo.jpg</bkgimage><headerimage>images/header.png</headerimage></config> */
 
   var config_xml:XML = tempconfig_xml.childNodes[1].childNodes;
   trace("config_xml: " + config_xml);
   // result
   /* config_xml: <bkgimage>images/bkg_browsevideo.jpg</bkgimage>,<headerimage>images/header.png</headerimage> */
   var var1 = tempconfig_xml.childNodes[1].childNodes[1].nodeName;
   var var2 = tempconfig_xml.childNodes[1].childNodes[1].nodeValue;
   var var3 = tempconfig_xml.childNodes[1].childNodes[1]
   trace("var1: " + var1); // var1: bkgimage
   trace("var2: " + var1); // var2: bkgimage -- I need it to be images/bkg_browsevideo.jpg
   trace("var3: " + var3); 
   //<bkgimage>images/bkg_browsevideo.jpg</bkgimage>
   stop();
}

Open in new window

0
Comment
Question by:katyjack
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
driscolltm earned 250 total points
ID: 20322168
two issues:

first you're tracing out var1 where you want to see var2:
trace("var2: " + var1);
needs to be
trace("var2: " + var2);

second, the text value within a node is actually a child node itself so:

var var2 = tempconfig_xml.childNodes[1].childNodes[1].nodeValue;
needs to be
var var2 = tempconfig_xml.childNodes[1].childNodes[1].childNodes[0].nodeValue;
   
0
 

Author Closing Comment

by:katyjack
ID: 31410175
That's absolutely correct - thanks very much. I'm not sure you'll see this or if there's a place for you to answer and I suppose I'm trying to get a freebie in here, but you're answer made me curious about one more thing - why would "var config_xml:XML = tempconfig_xml.childNodes[1].childNodes;" work, but "var config_xml:XML = tempconfig_xml.firstChild.childNodes;" throw a type mismatch error? I would think they would mean the same thing. At any rate - thanks very much for your help.
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
XML Document XPath with Namespaces 3 40
MS Access VBA Object Variable Not Set. Can't figure this out. 11 64
Replace value 2 55
XJS:  how to throw error if no match found 8 57
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question