views:

320

answers:

1

Hi, I am trying to parse a XML File using NSXMLParser, I also have a Container class, in which I have a few instance variables. One of the elements that I am trying to parse in the XML is:

<book sn="32.859669048339128" pn="-116.917800670489670">

I am trying to save the value of sn and pn in an instance variable of object Container: NSNumber *sn, NSNumber *pn.

I want it so that when my parser get the attributeValues it can save it as a Double (or float) in those NSNumber pointers.

Right now, all it does it just saves a string to the NSNumber.

The Parser Code looks like this:

if([elementName isEqualToString:@"book"]){

    container = [[Container alloc] init];

    container.sn=[attributeDict objectForKey:@"sn"];
    container.pn=[attributeDict objectForKey:@"pn"];
}

I want it so that the type of container.sn is initialized to a float or double. Any ideas how to do this?

Thanks in advance!

+3  A: 

So you want to take a float value in a string and create an NSNumber?

container.sn = [[NSNumber numberWithFloat:[string floatValue]];
Paul Lynch