Problem converting to INT from an XML file

Hi folks, I hope you can help with this one, as it's been driving me nuts...

Basically (and I'll try to keep this brief!) my project takes in an extremely basic XML file. I've never really done this before, but I seem to have got most of it working apart from taking in attribute values which I want to use as integers.

Essentially, each element relates to objects of a basic class I have set up, while each attribute relates to the variables for the object. When the XML file is read, a new object is set up for each element and is stored in a linked list. That was *supposed* to be the difficult bit, but it turns out it hasn't been...

The XML file looks a little bit like this (only the elements are shown to save space):

<Object name="My object" description ="blah" x_axis ="96" y_axis="23" />

<Object name="Another one" description ="blah, again" x_axis ="83" y_axis="40"/>

etc. etc.

The problem relates to the x_axis and y_axis attributes. While the description and name attributes are assigned correctly, for some reason the x_axis and y_axis attributes are both given values of zero when I convert them from Strings to Ints. After much printing to the console, kicking and screaming, I think I've narrowed the problem down to the following code:

if (attrib.getName() =="x_axis")

{

int myX = Integer.parseInt(attrib.getValue());// converting a string to an int

myObject.setSoundX_Axis(myX);

}

// And, of course, I do the same sort of thing for the Y axis.

Anyone know why I'm getting zero values? Is it something to do with the way I'm converting the string to an int in Java?

Cheers for any help.

[2133 byte] By [c0leya] at [2007-10-3 6:40:40]
# 1

> int myX = Integer.parseInt(attrib.getValue());

I don't see anything wrong. Try printing out the value of attrib.getValue() to see if it is what you expect. You may want to try:

String s = "" + myX;

if ( s.compareTo(attrib.getValue() != 0 ) {

System.out.println("Don't compare: myX=" + myX + " getValue=" + attrib.getValue());

}

orbacha at 2007-7-15 1:29:36 > top of Java-index,Java Essentials,New To Java...
# 2
You're right...after checking again, this bit of code isn't actually causing the problem, so something else may have caused the problem. I might get back to everyone once I've juggled the code around...
c0leya at 2007-7-15 1:29:36 > top of Java-index,Java Essentials,New To Java...
# 3
I think I've solved the problem!Turns out I'd re-set the object variables in another function (which I created several months ago), so it had nothing to do with the conversion at all. Doh. At least it means I can relax a little...
c0leya at 2007-7-15 1:29:36 > top of Java-index,Java Essentials,New To Java...
# 4
maybe, xstream
mchan0a at 2007-7-15 1:29:36 > top of Java-index,Java Essentials,New To Java...