NSXMLElement stores wrong value for even numbers

  • MacOS: 10.4.8
    Xcode:  2.4.1
    Topic: Tree-Base XML Programming for Cocoa

    Hello,
      This is my first publishing to the list, so advance apologies, if it's
    the wrong one or my content isn't clear.

    Problem: I have a routine to create NSXMLElement that should the
    following layout for NSNumbers
                      <Entry Type="NSNumber" Key="amount">(the
    number)</entry>,

      where "Key" is field in the GUI where the number goes. Below is the
    code fragement that is suppose to handle
      the NSNumber values:

    ...................
    -(NSXMLElement *)addElementValue:(NSXMLElement *)parent
    elementName:(NSString *)elementName value:(id)value
    showTypeAttribute:(BOOL)showType
    {
      //Add elemenet
      NSXMLElement *newElement = [self addElement:parent
    elementName:elementName];

      //Attach the value of the node
      // CHeck if class type is number, date, if not then default to string
      NSLog(@"value=<%@> class=<%@>", value, [value class]);
      if ([value isKindOfClass:[NSNumber class]])
        {
         [newElement setObjectValue:value];
          //[newElement setStringValue:value];
         if (showType)
           [newElement addAttribute:[self addDataTypeAttribute:value]];
         return newElement;
    }

    ...................

    The output to the XML file for (the number) = 30 is:
                <Entry Type="NSNumber" Key="amount">30E1</Entry>

    The output to the XML file for (the number) = 35 is:
                <Entry Type="NSNumber" Key="amount">3.5E1</Entry>

    The "output being" a write of the data via
      NSData *xmlData=[xmlDoc XMLDataWithOptions:NSXMLNodePrettyPrint];
      [xmlData writeToFile:aFileName atomically:YES];

    The problem is for ANY even numbers (ie 30), when the value is read back
    in, it becomes 300 (aka 30E1)
    For odd number (ie 35), when the value is read back in, its still 35
    (aka 3.5E1)
    I just picked 30 as an example, ANY even number 100 returns 1000, 50
    return 500, etc.
    Odd numbers work fine.

    I've tried "[newElement setObjectValue:value];"  and "[newElement
    setStringValue:value" with the same results.

    The trace for the NSLog(@"value=<%@> class=<%@>", value, [value class]);
    value=<30> class=<NSDecimalNumber>
    value=<35> class=<NSDecimalNumber>

    Thanks in advance for any advise/help/clues.

    Steven