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
Solved

preventing blank xml records outputting as undefined

Posted on 2006-07-13
2
234 Views
Last Modified: 2006-11-18
in my xml file i have a part of it that goes like this

<store>
<name>Harvey Norman Outlets</name>
<address></address>
<suburb></suburb>
<postcode></postcode>
<phone></phone>
</store>

which when it is output through flash it outputs as
Harvey Norman Outlets
undefined
undefined
undefined
undefined

in the dynamic text. thanks to aneeshchopra ive got all the stores to output now, but now i'm just left with this one problem there.

this is the code in the flash file.

function loadXML(loaded) {

if (loaded) {
dB = new Array();
for(var i =0; i < xmlData.firstChild.childNodes.length; i ++){
// this.firstChild.childNodes[] refers to which store record you refer to
// this.firstChild.childNodes[].ChildNodes[0] refers to the store name
// this.firstChild.childNodes[].ChildNodes[1] refers to the store address
// this.firstChild.childNodes[].ChildNodes[2] refers to the store suburb
// this.firstChild.childNodes[].ChildNodes[3] refers to the store phone

_root.presentation.Retailers.waslide.waholder.text += this.firstChild.childNodes[i].childNodes[0].firstChild.nodeValue +  newline + this.firstChild.childNodes[i].childNodes[1].firstChild.nodeValue + newline + this.firstChild.childNodes[i].childNodes[2].firstChild.nodeValue + newline + this.firstChild.childNodes[i].childNodes[3].firstChild.nodeValue + newline + newline;
}
} else {
trace("file not loaded!");
}
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("wa.xml");

thanks
0
Comment
Question by:paulp75
2 Comments
 
LVL 14

Expert Comment

by:trigger-happy
ID: 17098975
Try to add a little if statement in there that will check if the value of that certain node is undefined. If so then change the value to something else like an empty space " " so that you won't see the undefined message.

--trigger-happy
0
 
LVL 37

Accepted Solution

by:
CyanBlue earned 500 total points
ID: 17104040
What trigger-happy is saying is like this...

function loadXML(loaded)
{
      if (loaded)
      {
            dB = new Array();
            for(var i =0; i < xmlData.firstChild.childNodes.length; i ++)
            {
                  // this.firstChild.childNodes[] refers to which store record you refer to
                  // this.firstChild.childNodes[].ChildNodes[0] refers to the store name
                  // this.firstChild.childNodes[].ChildNodes[1] refers to the store address
                  // this.firstChild.childNodes[].ChildNodes[2] refers to the store suburb
                  // this.firstChild.childNodes[].ChildNodes[3] refers to the store phone
                  
                  var _store = this.firstChild.childNodes[i];
                  var _storeName = _store.childNodes[0].firstChild.nodeValue;
                  var _storeAddress = _store.childNodes[1].firstChild.nodeValue;
                  var _storeSuburb = _store.childNodes[2].firstChild.nodeValue;
                  var _storePhone = _store.childNodes[3].firstChild.nodeValue;
                  
                  if (_store == undefined) _store = "";
                  if (_storeName == undefined) _storeName = "";
                  if (_storeAddress == undefined) _storeAddress = "";
                  if (_storeSuburb == undefined) _storeSuburb = "";
                  if (_storePhone == undefined) _storePhone = "";
                  
                  _root.presentation.Retailers.waslide.waholder.text += _storeName +  newline + _storeAddress + newline + _storeSuburb + newline + _storePhone + newline + newline;
            }
      }
      else
      {
            trace("file not loaded!");
      }
}
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("wa.xml");

I think this sort of approach is whole lot more readable when you have to come back to the code like a month later...  That's the whole reason why I am replying to this topic...  ;)

CyanBlue
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

860 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