• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSXMLElement stores wrong value for even numbers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSXMLElement stores wrong value for even numbers


  • Subject: NSXMLElement stores wrong value for even numbers
  • From: "Smith, Steven (RSAA Storage)" <email@hidden>
  • Date: Wed, 29 Nov 2006 07:02:50 -0700
  • Thread-topic: 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
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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

  • Prev by Date: Re: Scaling Problem with CIAffineTransform
  • Next by Date: Re: New Cocoa Graphics Tutorial
  • Previous by thread: Re: Scaling Problem with CIAffineTransform
  • Next by thread: Modifying the dragged image during a drag / drop operation
  • Index(es):
    • Date
    • Thread