iPhone NSXMLParser parsing string and storing in a NSNumber variable and different data types

Posted by anubhav on Stack Overflow See other posts from Stack Overflow or by anubhav
Published on 2010-04-15T18:07:44Z Indexed on 2010/04/15 18:23 UTC
Read the original article Hit count: 564

Filed under:
|
|
|
|

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!

© Stack Overflow or respective owner

Related posts about nsxmlparser

Related posts about iphone