Permalink
Browse files

Merge pull request #505 from spenrose/xml-attributes-bug

This fixes a bug where attributes of a object would also get added to parent object.
  • Loading branch information...
2 parents d0b8594 + c6fd924 commit fa4491618415f063a940838dbd5833c9e8e29b3d Jeff Arena committed Jan 20, 2012
Showing with 5 additions and 2 deletions.
  1. +3 −1 Code/Support/Parsers/XML/RKXMLParserLibXML.m
  2. +2 −1 Specs/Support/RKXMLParserSpec.m
@@ -37,6 +37,8 @@ - (id)parseNode:(xmlNode*)node {
// Assume that empty strings are irrelevant and go for an attribute-collection instead
if ([val length] == 0) {
val = [NSMutableDictionary dictionary];
+ attrs = [NSMutableDictionary dictionary];
+ oldVal = [attrs valueForKey:nodeName];
NSMutableDictionary* elem = [NSMutableDictionary dictionaryWithObject:val forKey:nodeName];
[nodes addObject:elem];
} else {
@@ -50,7 +52,7 @@ - (id)parseNode:(xmlNode*)node {
}
// Only add attributes to nodes if there actually is one.
- if (![nodes containsObject:attrs]) {
+ if (![nodes containsObject:attrs] && [attrs count] > 0) {
[nodes addObject:attrs];
}
} else {
@@ -110,7 +110,8 @@ - (void)testShouldParseXMLWithAttributesInTextNodes {
NSDictionary* exchangeRate = [result objectForKey:@"exchange_rate"];
assertThat(exchangeRate, is(notNilValue()));
assertThat([exchangeRate objectForKey:@"type"], is(equalTo(@"XML_RATE_TYPE_EBNK_MIDDLE")));
- assertThat([exchangeRate objectForKey:@"valid_from"], is(equalTo(@"2011-08-03 00:00:00.0")));
+ assertThat([exchangeRate objectForKey:@"valid_from"], is(equalTo(@"2011-08-03 00:00:00.0")));
+ assertThat([exchangeRate objectForKey:@"name"], nilValue()); // This is to test for bug in parsing
NSArray* currency = [exchangeRate objectForKey:@"currency"];
assertThat(currency, hasCountOf(3));
NSDictionary* firstCurrency = [currency objectAtIndex:0];

0 comments on commit fa44916

Please sign in to comment.