Permalink
Browse files

Added modifications for attributes by Ben Sgro

  • Loading branch information...
1 parent 44e4329 commit 2e2c761123cebb274bc6333ac505b262847a0c24 Edward Patel committed May 12, 2010
Showing with 26 additions and 11 deletions.
  1. +6 −4 src/ListParser.h
  2. +19 −6 src/ListParser.m
  3. +1 −1 src/NameValueParser.m
View
@@ -30,15 +30,17 @@
NSMutableString *activeText;
NSMutableArray *list;
NSMutableArray *fieldNames;
+ NSMutableArray *attributeNames;
}
-+ (ListParser*)parser;
++ (ListParser *)parser;
- (id)init;
-- (void)parseData:(NSData*)data;
-- (void)parseString:(NSString*)string;
+- (void)parseData:(NSData *)data;
+- (void)parseString:(NSString *)string;
- (NSArray*)list;
- (int)numEntries;
-- (void)addFieldName:(NSString*)name;
+- (void)addFieldName:(NSString *)name;
+- (void)addAttributeName:(NSString *)name;
@end
View
@@ -28,7 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
@implementation ListParser
-+ (ListParser*)parser
++ (ListParser *)parser
{
return [[[ListParser alloc] init] autorelease];
}
@@ -38,6 +38,7 @@ - (id)init
if (self = [super init]) {
list = [[NSMutableArray alloc] init];
fieldNames = [[NSMutableArray alloc] init];
+ attributeNames = [[NSMutableArray alloc] init];
}
return self;
}
@@ -48,10 +49,11 @@ - (void)dealloc
[activeText release];
[list release];
[fieldNames release];
+ [attributeNames release];
[super dealloc];
}
-- (NSArray*)list
+- (NSArray *)list
{
return [NSArray arrayWithArray:list];
}
@@ -61,15 +63,15 @@ - (int)numEntries
return list.count;
}
-- (void)parseData:(NSData*)data
+- (void)parseData:(NSData *)data
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];
[parser parse];
[parser release];
}
-- (void)parseString:(NSString*)string
+- (void)parseString:(NSString *)string
{
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:[string dataUsingEncoding:NSUTF8StringEncoding]];
[parser setDelegate:self];
@@ -89,6 +91,12 @@ - (void) parser:(NSXMLParser *)parser
if ([fieldNames containsObject:elementName]) {
activeText = [[NSMutableString alloc] init];
}
+ unsigned count = [attributeNames count];
+ while (count--) {
+ if ([attributeDict objectForKey:[attributeNames objectAtIndex:count]]) {
+ [list addObject:[attributeDict valueForKey:[attributeNames objectAtIndex:count]]];
+ }
+ }
}
- (void)parser:(NSXMLParser *)parser
@@ -112,9 +120,14 @@ - (void)parser:(NSXMLParser *)parser
[activeText appendString:string];
}
-- (void)addFieldName:(NSString*)name
+- (void)addFieldName:(NSString *)name
{
[fieldNames addObject:[NSString stringWithString:name]];
}
-@end
+- (void)addAttributeName:(NSString *)name
+{
+ [attributeNames addObject:[NSString stringWithString:name]];
+}
+
+@end
@@ -146,4 +146,4 @@ - (void)addFieldName:(NSString*)name
[fieldNames addObject:[NSString stringWithString:name]];
}
-@end
+@end

0 comments on commit 2e2c761

Please sign in to comment.