Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case/Switch Statement 1

Status
Not open for further replies.

dmears1

Technical User
Jun 18, 2003
208
US
I am reading data from a XML file. I need to test the value of one of the nodes and then use a Swith/Case statement to test the value of one of the nodes. Below is my code:

Code:
_root.sixthnode = this.firstChild.childNodes[0].childNodes[6].firstChild.nodeValue;

var tmpCity = _root.sixthnode;

                trace(typeof(tmpCity)); //outputs string
		trace(tmpCity); // outputs MEM
		switch(tmpCity)
		{
			case 'MEM':
			tmpCity = 'Memphis';
			break;
			default:
                        trace("failure");
		}

When I trace tye typeof the tmpCity variable it is string. I've verified that tmpCity is MEM. However, I am entering the default case.

If anyone has any ideas why a trace shows that tmpCity is a string with a value of MEM, yet my case statement isn't working, I would appreciate any help.

 
Code:
//
var tmpCity = "MEM";
trace(tmpCity);
switch (tmpCity) {
case 'MEM' :
	tmpCity = 'Memphis';
	break;
default :
	trace("failure");
	break;
}
trace(tmpCity);
stop();
//
[tt]// Output
MEM
Memphis[/tt]

So basically your switch statement should be fine.

Kenneth Kawamoto
 
Is there any whitespace in your text? You may need to trim it up first.. try trace("tmpCity is '" + tmpCity + "'"); and make sure you don't see "tmpCity is 'MEM '" or something like that.

-Dustin
Rom 8:28
 
Thanks for the help. The issue was with whitespace. I had:
Code:
xmlData.ignoreWhite = true;
but it was not stripping out the whitespace. I added a function to strip it out and it works. Thanks again for the help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top