Differences From Artifact [bd82ff1d44]:
- File
src/OFXMLElement.m
— part of check-in
[ed63c0fdc1]
at
2010-07-29 19:32:33
on branch trunk
— Comply with section 6.2 of XML namespaces.
More specifically to this:
"The namespace name for an unprefixed attribute name always has no
value." (user: js, size: 10953) [annotate] [blame] [check-ins using]
To Artifact [e59c8082fb]:
- File src/OFXMLElement.m — part of check-in [9d6716470e] at 2010-09-08 21:17:46 on branch trunk — Fix Objective C++ compatibility. (user: js, size: 10892) [annotate] [blame] [check-ins using]
︙ | ︙ | |||
84 85 86 87 88 89 90 | { return [self initWithName: name_ namespace: nil stringValue: stringval]; } - initWithName: (OFString*)name_ | | | | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | { return [self initWithName: name_ namespace: nil stringValue: stringval]; } - initWithName: (OFString*)name_ namespace: (OFString*)ns_ { return [self initWithName: name_ namespace: ns_ stringValue: nil]; } - initWithName: (OFString*)name_ namespace: (OFString*)ns_ stringValue: (OFString*)stringval { self = [super init]; name = [name_ copy]; ns = [ns_ copy]; if (stringval != nil) { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init];; [self addChild: [OFXMLElement elementWithCharacters: stringval]]; [pool release]; } |
︙ | ︙ | |||
148 149 150 151 152 153 154 | - (OFString*)name { return [[name copy] autorelease]; } - (OFString*)namespace { | | | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 | - (OFString*)name { return [[name copy] autorelease]; } - (OFString*)namespace { return [[ns copy] autorelease]; } - (OFArray*)attributes { return [[attributes copy] autorelease]; } |
︙ | ︙ | |||
215 216 217 218 219 220 221 | i = 0; len = [name cStringLength] + 3; str_c = [self allocMemoryWithSize: len]; /* Start of tag */ str_c[i++] = '<'; | < | | | | < | < | 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 | i = 0; len = [name cStringLength] + 3; str_c = [self allocMemoryWithSize: len]; /* Start of tag */ str_c[i++] = '<'; if ((ns == nil && def_ns != nil) || (ns != nil && def_ns == nil) || (ns != nil && ![ns isEqual: def_ns])) { if ((prefix = [all_namespaces objectForKey: (ns != nil ? ns : (OFString*)@"")]) == nil) @throw [OFUnboundNamespaceException newWithClass: isa namespace: ns]; len += [prefix cStringLength] + 1; @try { str_c = [self resizeMemory: str_c toSize: len]; } @catch (OFException *e) { [self freeMemory: str_c]; @throw e; |
︙ | ︙ | |||
392 393 394 395 396 397 398 | [self addAttribute: [OFXMLAttribute attributeWithName: name_ namespace: nil stringValue: value]]; [pool release]; } - (void)addAttributeWithName: (OFString*)name_ | | | | | | | | | | | | | | | | | 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 | [self addAttribute: [OFXMLAttribute attributeWithName: name_ namespace: nil stringValue: value]]; [pool release]; } - (void)addAttributeWithName: (OFString*)name_ namespace: (OFString*)ns_ stringValue: (OFString*)value { OFAutoreleasePool *pool; if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; pool = [[OFAutoreleasePool alloc] init]; [self addAttribute: [OFXMLAttribute attributeWithName: name_ namespace: ns_ stringValue: value]]; [pool release]; } /* TODO: Replace attribute */ /* TODO: Remove attribute */ - (void)setPrefix: (OFString*)prefix forNamespace: (OFString*)ns_ { if (name == nil || prefix == nil || [prefix isEqual: @""]) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if (ns_ == nil) ns_ = @""; [namespaces setObject: prefix forKey: ns_]; } - (void)bindPrefix: (OFString*)prefix forNamespace: (OFString*)ns_ { [self setPrefix: prefix forNamespace: ns_]; [self addAttributeWithName: prefix namespace: @"http://www.w3.org/2000/xmlns/" stringValue: ns_]; } - (OFString*)defaultNamespace { if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; return [[defaultNamespace retain] autorelease]; } - (void)setDefaultNamespace: (OFString*)ns_ { if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; OFString *old = defaultNamespace; defaultNamespace = [ns_ copy]; [old release]; } - (void)bindDefaultNamespace: (OFString*)ns_ { [self setDefaultNamespace: ns_]; [self addAttributeWithName: @"xmlns" stringValue: ns_]; } - (void)addChild: (OFXMLElement*)child { if (name == nil) @throw [OFInvalidArgumentException newWithClass: isa selector: _cmd]; if (children == nil) children = [[OFMutableArray alloc] init]; [children addObject: child]; } - (void)dealloc { [name release]; [ns release]; [attributes release]; [namespaces release]; [children release]; [characters release]; [cdata release]; [comment release]; [super dealloc]; } @end |