Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

preventing blank xml records outputting as undefined

Posted on 2006-07-13
2
Medium Priority
?
242 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
[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 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
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…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

721 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