|
7 | 7 |
|
8 | 8 | @implementation NSXMLElement (XMPP)
|
9 | 9 |
|
| 10 | +/** |
| 11 | + * Convenience methods for Creating elements. |
| 12 | +**/ |
| 13 | + |
| 14 | ++ (NSXMLElement *)elementWithName:(NSString *)name numberValue:(NSNumber *)number |
| 15 | +{ |
| 16 | + return [self elementWithName:name stringValue:[number stringValue]]; |
| 17 | +} |
| 18 | + |
| 19 | +- (id)initWithName:(NSString *)name numberValue:(NSNumber *)number |
| 20 | +{ |
| 21 | + return [self initWithName:name stringValue:[number stringValue]]; |
| 22 | +} |
| 23 | + |
| 24 | ++ (NSXMLElement *)elementWithName:(NSString *)name objectValue:(id)objectValue |
| 25 | +{ |
| 26 | + if([objectValue isKindOfClass:[NSString class]]) |
| 27 | + { |
| 28 | + return [self elementWithName:name stringValue:objectValue]; |
| 29 | + } |
| 30 | + else if([objectValue isKindOfClass:[NSNumber class]]) |
| 31 | + { |
| 32 | + return [self elementWithName:name numberValue:objectValue]; |
| 33 | + } |
| 34 | + else if([objectValue respondsToSelector:@selector(stringValue)]) |
| 35 | + { |
| 36 | + return [self elementWithName:name stringValue:[objectValue stringValue]]; |
| 37 | + } |
| 38 | + else |
| 39 | + { |
| 40 | + return [self elementWithName:name]; |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +- (id)initWithName:(NSString *)name objectValue:(id)objectValue |
| 45 | +{ |
| 46 | + if([objectValue isKindOfClass:[NSString class]]) |
| 47 | + { |
| 48 | + return [self initWithName:name stringValue:objectValue]; |
| 49 | + } |
| 50 | + else if([objectValue isKindOfClass:[NSNumber class]]) |
| 51 | + { |
| 52 | + return [self initWithName:name numberValue:objectValue]; |
| 53 | + } |
| 54 | + else if([objectValue respondsToSelector:@selector(stringValue)]) |
| 55 | + { |
| 56 | + return [self initWithName:name stringValue:[objectValue stringValue]]; |
| 57 | + } |
| 58 | + else |
| 59 | + { |
| 60 | + return [self initWithName:name]; |
| 61 | + } |
| 62 | +} |
| 63 | + |
10 | 64 | /**
|
11 | 65 | * Quick method to create an element
|
12 | 66 | **/
|
@@ -273,6 +327,22 @@ - (void)addAttributeWithName:(NSString *)name numberValue:(NSNumber *)number
|
273 | 327 | [self addAttributeWithName:name stringValue:[number stringValue]];
|
274 | 328 | }
|
275 | 329 |
|
| 330 | +- (void)addAttributeWithName:(NSString *)name objectValue:(id)objectValue |
| 331 | +{ |
| 332 | + if([objectValue isKindOfClass:[NSString class]]) |
| 333 | + { |
| 334 | + [self addAttributeWithName:name stringValue:objectValue]; |
| 335 | + } |
| 336 | + else if([objectValue isKindOfClass:[NSNumber class]]) |
| 337 | + { |
| 338 | + [self addAttributeWithName:name numberValue:objectValue]; |
| 339 | + } |
| 340 | + else if([objectValue respondsToSelector:@selector(stringValue)]) |
| 341 | + { |
| 342 | + [self addAttributeWithName:name stringValue:[objectValue stringValue]]; |
| 343 | + } |
| 344 | +} |
| 345 | + |
276 | 346 | /**
|
277 | 347 | * The following methods return the corresponding value of the attribute with the given name.
|
278 | 348 | **/
|
|
0 commit comments