NSXMLNode bug in method XMLString
NSXMLNode bug in method XMLString
- Subject: NSXMLNode bug in method XMLString
- From: Kenneth Chin-Purcell <email@hidden>
- Date: Thu, 7 May 2009 21:39:23 -0500
I am a long time programmer returning to Mac development, so pardon if
I'm not following protocol. I submitted this bug to the Apple Bug
Reporter (id 6693016) about two months ago and it's just been sitting
there with no response. From my searching of the archives it seems
that no-one has reported this, so I'm submitting it here so at least
some other people can find it via Google.
The XMLString method of NSXMLNode gets it wrong for a NSNumber object,
set as an object, that is a simple power of ten. This bit me while
writing code to export data.
Here is a nice compact demo of the bug:
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
// Garbage collection required
NSNumber *numberOneHundred = [NSNumber numberWithDouble:100.0];
NSNumber *numberOneHundredAndSmidge = [NSNumber numberWithDouble:
100.01];
NSXMLElement *nodeGood1 = [NSXMLNode
elementWithName:@"Percentage" stringValue:[numberOneHundred
stringValue]];
NSXMLElement *nodeGood2 = [NSXMLNode
elementWithName:@"Percentage" stringValue:[numberOneHundredAndSmidge
stringValue]];
NSXMLElement *nodeGood3 = [NSXMLNode
elementWithName:@"Percentage"];
[nodeGood3 setObjectValue:numberOneHundredAndSmidge];
NSXMLElement *nodeError = [NSXMLNode
elementWithName:@"Percentage"];
[nodeError setObjectValue:numberOneHundred];
NSLog(@"Good1: %@", [nodeGood1 XMLString]);
NSLog(@"Good2: %@", [nodeGood2 XMLString]);
NSLog(@"Good3: %@", [nodeGood3 XMLString]);
NSLog(@"Error: %@", [nodeError XMLString]);
return 0;
}
Produces (XCode 3.1.2, OS X 10.5):
2009-03-17 21:28:15.002 XMLWriteBug[22663:10b] Good1: <Percentage>100</
Percentage>
2009-03-17 21:28:15.013 XMLWriteBug[22663:10b] Good2:
<Percentage>100.01</Percentage>
2009-03-17 21:28:15.015 XMLWriteBug[22663:10b] Good3:
<Percentage>1.0001E2</Percentage>
2009-03-17 21:28:15.015 XMLWriteBug[22663:10b] Error:
<Percentage>10E2</Percentage>
Notice that last line should be 1.0E2 or 1E2 or 10E1, but not 10E2
-- Ken Chin-Purcell
Bungalow Pottery
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden