Overview
Comment: | Add -[elementsForName:namespace:] to OFXMLElement. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
8732769f4c63edb449308214597b054c |
User & Date: | js on 2011-02-19 16:08:05 |
Other Links: | manifest | tags |
Context
2011-02-19
| ||
20:30 | Fix a sign issue in base64. check-in: 4d44bbf586 user: js tags: trunk | |
16:08 | Add -[elementsForName:namespace:] to OFXMLElement. check-in: 8732769f4c user: js tags: trunk | |
15:06 | OFXMLElement improvements. check-in: 2086095795 user: js tags: trunk | |
Changes
Modified src/OFXMLElement.h from [315d8e460f] to [5b6e0fb993].
︙ | ︙ | |||
307 308 309 310 311 312 313 314 | /** * Adds a child to the OFXMLElement. * * \param child Another OFXMLElement which is added as a child */ - (void)addChild: (OFXMLElement*)child; @end | > > > > > > > > > > > > > > | 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | /** * Adds a child to the OFXMLElement. * * \param child Another OFXMLElement which is added as a child */ - (void)addChild: (OFXMLElement*)child; /** * \param elemname The name of the elements * \return The child elements with the specified name */ - (OFArray*)elementsForName: (OFString*)elemname; /** * \param elemname The name of the elements * \param elemns The namespace of the elements * \return The child elements with the specified name and namespace */ - (OFArray*)elementsForName: (OFString*)elemname namespace: (OFString*)elemns; @end |
Modified src/OFXMLElement.m from [4c4b122bc4] to [ebee134ccb].
︙ | ︙ | |||
571 572 573 574 575 576 577 578 579 580 581 582 583 584 | selector: _cmd]; if (children == nil) children = [[OFMutableArray alloc] init]; [children addObject: child]; } - (void)dealloc { [name release]; [ns release]; [attributes release]; [namespaces release]; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | selector: _cmd]; if (children == nil) children = [[OFMutableArray alloc] init]; [children addObject: child]; } - (OFArray*)elementsForName: (OFString*)elemname { return [self elementsForName: elemname namespace: nil]; } - (OFArray*)elementsForName: (OFString*)elemname namespace: (OFString*)elemns { OFMutableArray *ret = [OFMutableArray array]; OFXMLElement **children_c = [children cArray]; size_t i, children_count = [children count]; if (elemns != nil) { for (i = 0; i < children_count; i++) if ([children_c[i]->ns isEqual: elemns] && [children_c[i]->name isEqual: elemname]) [ret addObject: children_c[i]]; } else { for (i = 0; i < children_count; i++) if (children_c[i]->ns == nil && [children_c[i]->name isEqual: elemname]) [ret addObject: children_c[i]]; } return ret; } - (void)dealloc { [name release]; [ns release]; [attributes release]; [namespaces release]; |
︙ | ︙ |
Modified tests/OFXMLElementTests.m from [dbaee50446] to [32f41396af].
︙ | ︙ | |||
27 28 29 30 31 32 33 34 35 36 37 38 39 40 | static OFString *module = @"OFXMLElement"; @implementation TestsAppDelegate (OFXMLElementTests) - (void)XMLElementTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *elem[4]; TEST(@"+[elementWithName:]", (elem[0] = [OFXMLElement elementWithName: @"foo"]) && [[elem[0] stringValue] isEqual: @"<foo/>"]) TEST(@"+[elementWithName:stringValue:]", (elem[1] = [OFXMLElement elementWithName: @"foo" | > | 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | static OFString *module = @"OFXMLElement"; @implementation TestsAppDelegate (OFXMLElementTests) - (void)XMLElementTests { OFAutoreleasePool *pool = [[OFAutoreleasePool alloc] init]; OFXMLElement *elem[4]; OFArray *a; TEST(@"+[elementWithName:]", (elem[0] = [OFXMLElement elementWithName: @"foo"]) && [[elem[0] stringValue] isEqual: @"<foo/>"]) TEST(@"+[elementWithName:stringValue:]", (elem[1] = [OFXMLElement elementWithName: @"foo" |
︙ | ︙ | |||
112 113 114 115 116 117 118 119 120 121 122 | R([elem[0] addChild: [OFXMLElement elementWithName: @"bar"]]) && [[elem[0] stringValue] isEqual: @"<foo foo='b&ar'><bar/></foo>"] && R([elem[2] addChild: [OFXMLElement elementWithName: @"bar" namespace: @"urn:objfw:test"]]) && [[elem[2] stringValue] isEqual: @"<objfw-test:foo test='test'><objfw-test:bar/></objfw-test:foo>"]) [pool drain]; } @end | > > > > > > | 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | R([elem[0] addChild: [OFXMLElement elementWithName: @"bar"]]) && [[elem[0] stringValue] isEqual: @"<foo foo='b&ar'><bar/></foo>"] && R([elem[2] addChild: [OFXMLElement elementWithName: @"bar" namespace: @"urn:objfw:test"]]) && [[elem[2] stringValue] isEqual: @"<objfw-test:foo test='test'><objfw-test:bar/></objfw-test:foo>"]) TEST(@"-[elementsForName:namespace:]", (a = [elem[2] elementsForName: @"bar" namespace: @"urn:objfw:test"]) && [a count] == 1 && [[[a firstObject] stringValue] isEqual: @"<bar xmlns='urn:objfw:test'/>"]) [pool drain]; } @end |