Overview
Comment: | Resolve attribute namespaces after all attributes have been parsed. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
4c57833cfaef9274895b32798f6c1c10 |
User & Date: | js on 2010-07-08 18:49:36 |
Other Links: | manifest | tags |
Context
2010-07-08
| ||
19:28 | Add special handling for xmlns in OFXMLElement. check-in: 8a71128e91 user: js tags: trunk | |
18:49 | Resolve attribute namespaces after all attributes have been parsed. check-in: 4c57833cfa user: js tags: trunk | |
10:04 | Clean up method replacing. check-in: fdcb2a71e4 user: js tags: trunk | |
Changes
Modified src/OFXMLAttribute.h from [7a67ed7d56] to [7726e95a54].
︙ | ︙ | |||
14 15 16 17 18 19 20 21 22 23 24 25 26 27 | @class OFString; /** * \brief A representation of an attribute of an XML element as an object. */ @interface OFXMLAttribute: OFObject { OFString *name; OFString *namespace; OFString *stringValue; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain) OFString *name; | > | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | @class OFString; /** * \brief A representation of an attribute of an XML element as an object. */ @interface OFXMLAttribute: OFObject { @public OFString *name; OFString *namespace; OFString *stringValue; } #ifdef OF_HAVE_PROPERTIES @property (readonly, retain) OFString *name; |
︙ | ︙ |
Modified src/OFXMLParser.m from [bc650a7105] to [86d4782143].
︙ | ︙ | |||
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | if ((tmp = [carray[i] objectForKey: prefix]) != nil) return tmp; } return nil; } @implementation OFXMLParser + parser { return [[[self alloc] init] autorelease]; } | > > > > > > > > > > > > > > > > > > > > > > > > > | 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | if ((tmp = [carray[i] objectForKey: prefix]) != nil) return tmp; } return nil; } static OF_INLINE void resolve_attr_namespace(OFXMLAttribute *attr, OFString *prefix, OFString *ns, OFArray *namespaces, Class isa) { OFString *attr_ns; OFString *attr_prefix = attr->namespace; if ([[attr name] isEqual: @"xmlns"] && attr_prefix == nil) { [attr->namespace release]; attr->namespace = nil; return; } attr_ns = namespace_for_prefix( (attr_prefix != nil ? attr_prefix : prefix), namespaces); if ((attr_prefix != nil && attr_ns == nil) || (ns != nil && attr_ns == nil)) @throw [OFUnboundNamespaceException newWithClass: isa prefix: attr_prefix]; [attr->namespace release]; attr->namespace = [attr_ns retain]; } @implementation OFXMLParser + parser { return [[[self alloc] init] autorelease]; } |
︙ | ︙ | |||
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | } break; /* Inside a tag, name found */ case OF_XMLPARSER_IN_TAG: if (buf[i] == '>' || buf[i] == '/') { OFString *ns; ns = namespace_for_prefix(prefix, namespaces); if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException newWithClass: isa prefix: prefix]; pool = [[OFAutoreleasePool alloc] init]; [delegate parser: self didStartElement: name withPrefix: prefix namespace: ns attributes: attrs]; | > > > > > > | 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | } break; /* Inside a tag, name found */ case OF_XMLPARSER_IN_TAG: if (buf[i] == '>' || buf[i] == '/') { OFString *ns; OFXMLAttribute **attrs_c = [attrs cArray]; size_t j, attrs_cnt = [attrs count]; ns = namespace_for_prefix(prefix, namespaces); if (prefix != nil && ns == nil) @throw [OFUnboundNamespaceException newWithClass: isa prefix: prefix]; for (j = 0; j < attrs_cnt; j++) resolve_attr_namespace(attrs_c[j], prefix, ns, namespaces, isa); pool = [[OFAutoreleasePool alloc] init]; [delegate parser: self didStartElement: name withPrefix: prefix namespace: ns attributes: attrs]; |
︙ | ︙ | |||
426 427 428 429 430 431 432 | last = i + 1; state = OF_XMLPARSER_IN_ATTR_VALUE; break; /* Looking for attribute value */ case OF_XMLPARSER_IN_ATTR_VALUE: if (buf[i] == delim) { | < < < < | < < | | 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 491 492 493 494 495 496 497 | last = i + 1; state = OF_XMLPARSER_IN_ATTR_VALUE; break; /* Looking for attribute value */ case OF_XMLPARSER_IN_ATTR_VALUE: if (buf[i] == delim) { OFString *attr_val; len = i - last; if (len > 0) [cache appendCStringWithoutUTF8Checking: buf + last length: len]; pool = [[OFAutoreleasePool alloc] init]; attr_val = transform_string(cache, self); if (attrPrefix == nil && [attrName isEqual: @"xmlns"]) [[namespaces lastObject] setObject: attr_val forKey: @""]; if ([attrPrefix isEqual: @"xmlns"]) [[namespaces lastObject] setObject: attr_val forKey: attrName]; if (attrs == nil) attrs = [[OFMutableArray alloc] init]; [attrs addObject: [OFXMLAttribute attributeWithName: attrName namespace: attrPrefix stringValue: attr_val]]; [pool release]; [cache setToCString: ""]; [attrName release]; [attrPrefix release]; |
︙ | ︙ |