View Full Version : problem parsing xml, simple question (resolved)

Coastal Web
02-09-2008, 02:09 AM
Greetings folks,

I've attempting to parse in the contents of an xml file and l'm running into a bit of a wall... I'm trying to read data from that is a nodeType of 3 (text) ex: <name>textual value</name> but no matter what l do, actionscript thinks that the nodeType is 1 ex: <name src="textual value" />...

I've watered everythign down as much as possible to make it easy for anyone willing to take a look.

Here's my xml file:

<?xml version="1.0" encoding="iso-8859-1"?>
<title>title here</title>
<desc>descripotion here.. descripotion here... descripotion here... descripotion here... </desc>
<img src="pic1.jpg" />

And here's the Actionscript l'm using:

xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
} else {
trace('could not load xml file!');

I would expect the trace commands to output:

title here
descripotion here.. descripotion here... descripotion here... descripotion here...

in this example, however the following is what l get:


Upon closer inspection, the actionscript thinks that the ladder three nodes are type 1, and note type 3 (text)... any idea how to fix this?
If someone could let me know what l'm doing wrong l would really appreciate it, l'm sure it's a mundane oversight on my part... :S

02-09-2008, 04:52 AM
xmlNode.childNodes[0].childNodes[0] reaches down to the title element and any element node's nodeValue is null. only text nodes have nodeValue defined so, changing to xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue should solve your problem

Coastal Web
02-09-2008, 06:03 AM
Awesome, shyam ...

did the trick perfectly... +karma and +thanks...

Warm regards,