Display number of XML elements in a textfield - ios

I have an XML file somewhere on the web with a couple of profiles inside it and I want the number of profiles to be displayed in a textfield.
I have a textfield called: numberOfProfiles.. so what should I do in viewDidLoad?
numberOfProfiles.Text = ???
The XML file is being parsed like this:
NSMutableString *currentNodeContent;
NSXMLParser *parser;
ViewController *currentProfile;
bool isStatus;
ViewController *xmlParser;
-(id)loadXMLByURL:(NSString *)urlString
{
profile = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"firstname"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"lastname"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"email"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"address"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:#"firstname"])
{
currentProfile->firstName = currentNodeContent;
NSLog(#"%#",currentProfile->firstName);
[profile addObject:currentProfile];
}
if([elementName isEqualToString:#"lastname"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
[profile addObject:currentProfile];
}
if([elementName isEqualToString:#"email"])
{
currentProfile->eMail = currentNodeContent;
NSLog(#"%#",currentProfile->eMail);
[profile addObject:currentProfile];
}
if([elementName isEqualToString:#"address"])
{
currentProfile->address = currentNodeContent;
NSLog(#"%#",currentProfile->address);
[profile addObject:currentProfile];
}
if([elementName isEqualToString:#"profiles"])
{
[self->profile addObject:currentProfile];
currentProfile = nil;
currentNodeContent = nil;
setText:currentProfile->lastName;
}
}
- (void)viewDidLoad
{
[super viewDidLoad];
xmlParser = [[ViewController alloc] loadXMLByURL:#"http://dierenpensionlindehof.nl/profiles.xml"];
}
Thanks in advance!

for just count of element you can have an instance variable like of int type numberOfProfilesCount and you can increment this in
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
numberOfProfilesCount++;
}
and in
- (void)parserDidEndDocument:(NSXMLParser *)parser {
numberOfProfiles.Text = [NSString stringWithFormate:#"%d", numberOfProfilesCount];
}
to show your element count

Assuming profile is a global variable, use [profile count] to get the number of profiles.
The try: [numberOfProfiles setText:[[profile count] stringValue]

Related

How to display XML parsed data in UILabel

I am trying to display the data parsed from an XML file from the web to a UILabel called profilesLabel.
I'm trying to display all the lastName's in the label, but the value is set to the email address for some reason. Can someone help me understand why as I'm new to objective-c
here is the code:
-(id)loadXMLByURL:(NSString *)urlString
{
profile = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"firstname"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"lastname"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"email"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
if([elementName isEqualToString:#"address"])
{
currentProfile = [ViewController alloc];
isStatus = YES;
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if([elementName isEqualToString:#"firstname"])
{
currentProfile->firstName = currentNodeContent;
NSLog(#"%#",currentProfile->firstName);
}
if([elementName isEqualToString:#"lastname"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"email"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"address"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"profiles"])
{
[self->profile addObject:currentProfile];
currentProfile = nil;
currentNodeContent = nil;
}
}
- (IBAction)bringFont:(id)sender
{
//Here is a button that should show the parsed data in profilesLabel when pressed
profilesLabel.text = currentProfile->lastName; //Shows email address for some reason
//What I want is to show every single profile in profilesLabel underneath each other
}
- (void)viewDidLoad
{
[profilesScrolView setScrollEnabled:YES];
[profilesScrolView setContentSize:CGSizeMake(680, 1200)];
[super viewDidLoad];
xmlParser = [[ViewController alloc] loadXMLByURL:#"http://dierenpensionlindehof.nl/XML_File.xml"];
}
Any help would be appreciated, Tahnks!
is the issue that here:
if([elementName isEqualToString:#"profiles"])
{
[self->profile addObject:currentProfile];
currentProfile = nil;
currentNodeContent = nil;
}
you are setting currentProfile to nil
and then using currentProfile here:
- (IBAction)bringFont:(id)sender
{
//Here is a button that should show the parsed data in profilesLabel when pressed
profilesLabel.text = currentProfile->lastName;
EDIT:
After clarification that the issue was wanting to know how to display different data.
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
...
// At the end of each loop add current profile to the mutable array
[profile addObject:currentProfile];
// Now you can set currentProfile to nil
currentProfile = nil;
}
- (IBAction)bringFont:(id)sender
{
// If you want to display all of this data I would recommend creating a
// UITableView and have each entry as a row's title. But thats another
// issue so to set them all into the label as you asked:
// Loop through the array and add the strings together adding a newline each time
NSMutableString *str = [[NSMutableString alloc] init];
for(NSObject *obj in profile)
{
// Obj will need to be casted to whatever type 'currentProfile' is
[str appendFormat:#"\n %#", obj->lastName];
}
// Compute what height the UILabel needs to be to display this string
CGSize expectedSize = [str sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]] constrainedToSize:CGSizeMake(320, 9999) lineBreakMode:NSLineBreakByWordWrapping];
CGRect newFrame = CGRectMake(0, 0, expectedSize.width, expectedSize.height);
[profilesLabel setFrame:newFrame];
[profilesLabel setText:str];
}
EDIT 2:
After yet more clarification that the issue is that you don't have the last names, please draw your attention to the fact that you are assigning everything to lastName in this function:
if([elementName isEqualToString:#"lastname"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"email"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
if([elementName isEqualToString:#"address"])
{
currentProfile->lastName = currentNodeContent;
NSLog(#"%#",currentProfile->lastName);
last_Name.text = currentProfile->lastName;
}
in every section you use: currentProfile->lastName = currentNodeContent; you need to set the other values inside currentProfile !!!

how to parse xml response in NSDictionary in iPhone

I am trying to parse xml response and want data in NSDictionary.how can I get data in dictionary instead of NSMutableArray. Please help me ,getting response like :
<NewDataSet>
<Table>
<ID>105</ID>
<pk3>Apr 05, 2013</pk3>
<YEAR>2013</YEAR>
<TIME>09:10:46 PM</TIME>
</Table>
</NewDataSet>
Thanks in advance.
You can try with this..
.h /////////////////
#interface LoginWithTauky:UIViewController<NSXMLParserDelegate,NSURLConnectionDelegate>
{
NSXMLParser *xmlParser;
NSMutableString *soapResults;
BOOL xmlResults;
}
.m //////////////
-(void)Viewdidload
{
xmlParser = [[NSXMLParser alloc] initWithData:XMLdata];
[xmlParser setDelegate: self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
NSLog(#"fsdfsd");
if( [elementName isEqualToString:#"Table"]||[elementName isEqualToString:#"ID"]||[elementName isEqualToString:#"pk3"]||[elementName isEqualToString:#"YEAR"]||[elementName isEqualToString:#"TIME"])
{
if(!soapResults)
{
soapResults = [[NSMutableString alloc] init];
}
xmlResults = YES;
}
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if( xmlResults )
{
[soapResults appendString: string];
NSLog(#"soap result %#",soapResults);
}
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if( [elementName isEqualToString:#"Table"])
{
xmlResults = FALSE;
[user_idArray addObject:soapResults];
soapResults = nil;
}
if( [elementName isEqualToString:#"ID"])
{
xmlResults = FALSE;
[IDArray addObject:soapResults];
soapResults = nil;
}
if( [elementName isEqualToString:#"pk3"])
{
xmlResults = FALSE;
[IDArray addObject:soapResults];
soapResults = nil;
}
if( [elementName isEqualToString:#"YEAR"])
{
xmlResults = FALSE;
[IDArray addObject:soapResults];
soapResults = nil;
}
if( [elementName isEqualToString:#"TIME"])
{
xmlResults = FALSE;
[IDArray addObject:soapResults];
soapResults = nil;
}
}
This works fine , i have tested it. Check it out
-(IBAction)parseTheXml:(id)sender
{
NSString * mystr =[[NSString alloc]initWithFormat:#"<NewDataSet>"
"<Table>"
"<ID>105</ID>"
"<pk3>Apr 05, 2013</pk3>"
"<YEAR>2013</YEAR>"
"<TIME>09:10:46 PM</TIME>"
"</Table>"
"</NewDataSet>" ];
NSData * mydata =[mystr dataUsingEncoding:NSUTF8StringEncoding];
if(!parser)
parser =[[NSXMLParser alloc]initWithData:mydata];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:YES];
BOOL success= [parser parse];
if(success)
{
NSLog(#"SUCCESS");
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(#"the tag is %#",elementName);
if(!([elementName isEqualToString:#"Table"] ||[elementName isEqualToString:#"NewDataSet"]))
{
if(!dataDict)
dataDict =[[NSMutableDictionary alloc]init];
datastring =[[NSMutableString alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
datastring = [NSMutableString stringWithFormat:#"%#",string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(!([elementName isEqualToString:#"Table"] ||[elementName isEqualToString:#"NewDataSet"]))
{
if([elementName isEqualToString:#"VideoThumbnail"])
NSLog(#"the string is : %#",datastring);
[dataDict setObject:datastring forKey:elementName];
}
}
it will give you dictionary like this :
2013-12-05 16:24:05.959 parsingXML[3305:c07] the string we get is {
ID = 105;
TIME = "09:10:46 PM";
YEAR = 2013;
pk3 = "Apr 05, 2013";
}

parsing media content from yahoo rss feed xcode 4.5 ios

I'm trying to obtain the url contained in media:content tag of the Yahoo RSS feed. The code for didStartElement(), foundCharacters() and didEndElement() is given below:
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:kChannelElementName]) {
Channel = [[channel alloc] init];
dict=[[NSMutableDictionary alloc] init];
[Channel setItemCollectionArray:[[NSMutableArray alloc] init]];
return ;
}
if ([elementName isEqualToString:kItemElementName]) {
itemCollection=[[ItemDataCollection alloc] init];
return ;
}
if ([elementName isEqualToString:kTitleElementName]) {
return ;
}
if([elementName isEqualToString:kItemDescription]){
return ;
}
if ([elementName isEqualToString:kItemImage]) {
NSString *urlString = attributeDict[#"url"];
if(urlString){
[dict setObject:urlString forKey:#"img"];
}
return ;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
if (currentElementData == nil) {
self.currentElementData = [[NSMutableString alloc] init];
}
[currentElementData appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:kChannelElementName]) {
[channelCollection addObject:Channel];
NSLog(#"channel are***********%#",channelCollection);
for(ItemDataCollection *mydata in Channel.itemCollectionArray){
NSLog(#"___%# <><><><><> desc \n %# <><><><><><> img \n %#",mydata.title,mydata.itemDescription,mydata.titleImage);
}
Channel =nil;
}
else if ([elementName isEqualToString:kItemElementName]) {
[[Channel itemCollectionArray] addObject:itemCollection];
itemCollection=nil;
}
else if ([elementName isEqualToString:kTitleElementName]) {
if(itemCollection==nil){
Channel.title=currentElementData;
}
else{
itemCollection.title=currentElementData;
}
}
else if ([elementName isEqualToString:kPubDate]) {
Channel.pubDate=currentElementData;
}
else if ([elementName isEqualToString: kItemDescription]) {
if(itemCollection!=nil){
itemCollection.itemDescription=currentElementData;
}
}
else if([elementName isEqualToString:#"media:content"]){
if(itemCollection!=nil){
itemCollection.titleImage = currentElementData;
}
}
// [currentElementData release];
self.currentElementData = nil;
}
I'm printing the parsed data as log. The image is showing as null. Everything else eg;title and description is getting obtained properly. How can I fix it? Probably something needs to be done in the didEndElement method. But I don't know what. I've been racking my brains over this since yesterday. Please help!!
I made some changes in didStartElement():
if ([elementName isEqualToString:kItemImage]) {
NSString *urlString = attributeDict[#"url"];
if(urlString){
[dict setObject:urlString forKey:#"img"];
NSLog(#"%#",urlString);
mString = [NSString stringWithFormat:urlString];
and some change in didEndElement():
else if([currentElementData rangeOfString:#"media:content"].location){
if(itemCollection!=nil){
// [currentElementData appendString:dict];
itemCollection.titleImage = mString;
}
}
mString has been declared as a mutable string. Images are getting parsed now. Their urls are getting displayed in the log. The problem is that now, the last image is repeated twice.. It is probably because the last feed does not have an image, so it is using the previous one. How to fix that? I mean, there can be multiple feeds without images. in that case, it should actually display null rather than the url of the previous image.
I don`t know well about Yahoo rss feed but i hope it will help you.....
Just tryout this....
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
currentElement = [elementName copy];
if ([elementName isEqualToString:#"item"]) {
item = [[NSMutableDictionary alloc] init];
currentTitle = [[NSMutableString alloc] init];
currentDate = [[NSMutableString alloc] init];
currentSummary = [[NSMutableString alloc] init];
currentLink = [[NSMutableString alloc] init];
currentImage = [[NSMutableString alloc] init];
}
else if([elementName isEqualToString:#"media:content"]) {
currentImage = [attributeDict objectForKey:#"img src"];
NSLog(#"Url:%#", currentImage);
}
}
}

Twitter Feed not showing full tweet

So I am making an app that one part of it displays the users tweets in a table view. However there's something getting corrupted with some tweets such as its only showing a single character such as (") or an emoji character. In example if the tweet says:
RT #jakemillermusic: Everyone upload your pics that you took today during the ustream and caption it "follow #jakemillermusic #jakemiller"
when shown with NSLog it prints :
2013-04-03 00:34:30.476 ParsingXMLTutorial[3308:c07] RT #jakemillermusic: Everyone upload your pics that you took today during the ustream and caption it
2013-04-03 00:34:30.476 ParsingXMLTutorial[3308:c07] "
2013-04-03 00:34:30.477 ParsingXMLTutorial[3308:c07] follow #jakemillermusic #jakemiller
2013-04-03 00:34:30.478 ParsingXMLTutorial[3308:c07] "
Here's the URL I am using to fetch the XML format:
http://api.twitter.com/1/statuses/user_timeline/LexxiSaal.xml?include_entities=true&include_rts=true&screen_name=twitterapi&trim_user=false&contributor_details=true&count=50
HERES THE PARSING CODE:
-(id) loadXMLByURL:(NSString *)urlString
{
_tweets = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
//string = [string stringByReplacingOccurrencesOfString:#" " withString:#""]; // space
string = [string stringByReplacingOccurrencesOfString:#"\n" withString:#""]; // newline
string = [string stringByReplacingOccurrencesOfString:#"\t" withString:#""];
currentNodeContent = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:#"status"])
{
currentTweet = [Tweet alloc];
isStatus = YES;
}
if ([elementname isEqualToString:#"user"])
{
isStatus = NO;
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (isStatus)
{
if ([elementname isEqualToString:#"created_at"])
{
currentTweet.dateCreated = currentNodeContent;
}
if ([elementname isEqualToString:#"text"])
{
currentTweet.content = currentNodeContent;
}
}
if ([elementname isEqualToString:#"status"])
{
[self.tweets addObject:currentTweet];
currentTweet = nil;
currentNodeContent = nil;
}
}
#end
I would suggest few changes as below
- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
NSString *value=[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet];
if(currentNodeContent == nil){
currentNodeContent = [[NSMutableString alloc] initWithString:value];
}else
[currentNodeContent appendString:value];
}
and in didEnd
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (isStatus)
{
if ([elementname isEqualToString:#"created_at"])
{
currentTweet.dateCreated = currentNodeContent;
}
if ([elementname isEqualToString:#"text"])
{
currentTweet.content = currentNodeContent;
}
}
if ([elementname isEqualToString:#"status"])
{
[self.tweets addObject:currentTweet];
currentTweet = nil;
//currentNodeContent = nil; REMOVED
}
currentNodeContent = nil; // PUT OUTSIDE
}
The thing is you have to append string in method foundCharacters because the parser doesn't return all the string in between the tags at once..
And at last you should make the currentNodeContent nil, in the didEnd method globally because you are using it for other texts too.
Hope above helps..

Parsed xml file but the array is showing null

I have parsed the xml file.
The console is showing the parsed elements correctly but the array is showing null.
- (ParserClass *) initXMLParser
{
//[super init];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
return self;
}
- (void)parser: (NSXMLParser *)parser didStartElement:(NSString *) elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:#"note"]) {
//Initialize the array.
appDelegate.testArray = [[NSMutableArray alloc] init];
}
else if([elementName isEqualToString:#"to"]) {
aTest = [[Test alloc] init];
}
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;
if([elementName isEqualToString:#"note"]) {
[appDelegate.testArray addObject:aTest];
//[aBook release];
aTest = nil;
}
else
[aTest setValue:currentElementValue forKey:elementName];
//[currentElementValue release];
currentElementValue = nil;
}
#end
Try to change your initialization to:
- (ParserClass *) initXMLParser {
self=[super init];
if(self !=nil){
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
// init array of user objects here
appDelegate.testArray = [[NSMutableArray alloc] init];
}
return self;
}
And,if your xml is:
<books>
<note>
<something>cccc</something>
</note>
<note>
<something>cccc</something>
</note>
</books>
So you need change:
-(void)parser: (NSXMLParser *)parser didStartElement:(NSString *) elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if([elementName isEqualToString:#"note"]) {
aTest = [[Test alloc] init];
//if you have attributes, you can extract them here:
// user.att = [[attributeDict objectForKey:#"<att name>"] ...];
}
NSLog(#"Processing Element: %#", elementName);
}
And to get your array you must do something like this:
//Data store your xml
NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithData:Data];
ParserClass *parser = [[ParserClass alloc] initXMLParser];
//delegate your parser
[nsXmlParser setDelegate:parser];
//it's doing parsing
BOOL success = [nsXmlParser parse];
if (success)
{
NSMutableArray *someArray = [parser appDelegate.testArray ];
NSLog(#"%#",someArray );
} else
{
NSLog(#"Error parsing document!");
}
try it , it working for me...

Resources