Saturday, 7 September 2013

XML Parsing, Joining elements in iOS

XML Parsing, Joining elements in iOS

I've been trying to figure this out for a little while, but can't work it
out. Hopefully someone on here will have an idea.
I have some XML data that i am parsing, It looks like:
<Name>MAC 101</Name>
<Modes>
<Mode>
<Name>Basic RGB</Name>
<ChannelCount>8</ChannelCount>
</Mode>
<Mode>
<Name>Raw RGB</Name>
<ChannelCount>12</ChannelCount>
</Mode>
</Modes>
What I am doing is saving the info to an SQLite database, However i need
to combine some info into 1 string first. I need the string to look like:
(with the line break)
8 Basic RGB
12 Raw RGB
However sometimes there will be multiple "Modes" this example only has 2,
sometimes it could be a dozen or more.
The current code i'm using is NSXMLParser:
-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if (isStatus) {
if ([elementName isEqualToString:@"Name"]) {
CurrentFixture.Title = currentNodeContent;
NSLog(@"Name: %@",currentNodeContent);
}
if ([elementName isEqualToString:@"Name"]) {
CurrentFixture.ModeName = currentNodeContent;
NSLog(@"Mode Name: %@",currentNodeContent);
}
if ([elementName isEqualToString:@"ChannelCount"]) {
CurrentFixture.ChannelCount = currentNodeContent;
NSLog(@"Channel Count: %@",currentNodeContent);
}
}
if ([elementName isEqualToString:@"Fixture"]) {
NSLog(@"Do something with data.");
[self.data addObject:CurrentFixture];
NSLog(@"Data: %@",);
CurrentFixture = nil;
currentNodeContent = nil;
}
}
The Mode name will be changing tags so it doesn't get confused with the
actual name, But at the moment I just need to get something working. Any
advise or guidance would be much appreciated. Thanks Andrew

No comments:

Post a Comment