Re: iPhone XML Parse

Rui Lopes <[email protected]>
Newsgroups gmane.comp.macosx.devel
Message-ID <[email protected]>
Hi,

One example:

...

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {

if([elementName isEqualToString:@"Books"]) {
//Initialize the array.
appDelegate.books = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:@"Book"]) {

//Initialize the book.
aBook = [[Book alloc] init];

//Extract the attribute here.
aBook.bookID = [[attributeDict objectForKey:@"id"] integerValue];

NSLog(@"Reading id value :%i", aBook.bookID);
}

NSLog(@"Processing Element: %@", elementName);
}


- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

if(!currentElementValue)
currentElementValue = [[NSMutableString alloc] initWithString:string];
else
[currentElementValue appendString:string];

NSLog(@"Processing Value: %@", currentElementValue);

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

if([elementName isEqualToString:@"Books"])
return;

//There is nothing to do if we encounter the Books element here.
//If we encounter the Book element howevere, we want to add the book object to the array
// and release the object.
if([elementName isEqualToString:@"Book"]) {
[appDelegate.books addObject:aBook];

[aBook release];
aBook = nil;
}
else
[aBook setValue:currentElementValue forKey:elementName];

[currentElementValue release];
currentElementValue = nil;
}


All of these, go into the .m, correct?

If I have an xml file with 3 companys, each with 6 factorys, and each factory with the attributs, how do I populate a table the companys, for example?


Rui

A 2010/03/01, às 20:44, Fritz Anderson escreveu:

> On 1 Mar 2010, at 2:34 PM, Rui Lopes wrote:
> 
>> I've been reading the Apple docs, and some tutorials on the web, but i don't understand why there are 3 voids, with the same name, and what they do...
> 
> I don't understand what you mean by "3 voids." Are these method-return values? void*'s somewhere? Can you give us some clue to what API you're talking about?
> 
> As far as I know, your only option in Cocoa Touch for parsing XML is class NSXMLParser; see the class reference and "Event-Driven XML Programming Guide for Cocoa." It's not hard to get started with. 
> 
> 	— F
> 



Rui Lopes
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.