I am currently trying to get my parser delegates to work with a custom NSObject
I have created for the attributes of the xml I am receiving..
This is the XML that is being read in to my parser delegates
<Rows>
<Row SKATERID="706" MANUFACTURER="GAZ" ISFACT="F" ISSKATE="F"/>
<Row SKATERID="318" MANUFACTURER="MAN" ISFACT="F" ISSKATE="T"/>
//...
</Rows>
This is what I have for my -parser:didStartElement:namespaceURI:qualifiedName:attributes:
method:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ( [elementName isEqualToString:@"Row"]) {
manufactureNSObject = [[ManufactureNSObject alloc] init];
manufactureNSObject.ISFACT = [attributeDict objectForKey:@"ISFACT"];
manufactureNSObject.ISSKATE = [attributeDict objectForKey:@"ISSKATE"];
manufactureNSObject.MANUFACTURER = [attributeDict objectForKey:@"MANUFACTURER"];
manufactureNSObject.SKATERID = [attributeDict objectForKey:@"SKATERID"];
NSLog(@"%@ %@ %@ %@", manufactureNSObject.ISFACT, manufactureNSObject.ISSKATE, manufactureNSObject.MANUFACTURER, manufactureNSObject.SKATERID);
}
}
My NSLog
prints out all of the correct values fine, the next part that I am stuck on is the
- parser:didEndElement:namespaceURI:qualifiedName:
method, nothing apart from the didEndElement
is coming through correctly... this is what I have for that method.
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(@"%@", elementName);
NSLog(@"%@", namespaceURI);
NSLog(@"%@", qName);
}
This is what my output looks like from the NSLog
s.
2011-10-13 10:04:16.529 Code[52605:207] F F GAZ 76
2011-10-13 10:04:16.531 Code[52605:207] Row
2011-10-13 10:04:16.535 Code[52605:207] (null)
2011-10-13 10:04:16.537 Code[52605:207] (null)
2011-10-13 10:04:16.537 Code[52605:207] F T MAN 38
2011-10-13 10:04:16.538 Code[52605:207] Row
2011-10-13 10:04:16.539 Code[52605:207] (null)
2011-10-13 10:04:16.540 Code[52605:207] (null)
I specifically would like help with trying to complete the second method and get this all working correctly.
All the help so far has been greatly appreciated.
Create an interface
NSMutableString
that you can pass the string fromparser:foundCharacters
into. From there, implement a similar structure as you did inparser:didStartElement:
only this time, you'll use thatNSMutableString
and pass its value into the object that is represented by the element being closed.For the type of xml file you are parsing, the
is never called. This delegate method is called in such cases:while in your case only attributes are present and no tag content, that is:
As far as the other method:
its implementation is up to you. E.g. if you store an element inside a temporary variable then this method is useful to copy this variable inside another data structure.
Just incase someone checks this page out in the future I have found out how to do this
predicate are your friend.. and they are also good at isolating the values you want from a dictionary...
BOOM!