• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: xml parsing
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: xml parsing


  • Subject: Re: xml parsing
  • From: Alexander von Below <email@hidden>
  • Date: Wed, 01 Apr 2009 19:17:19 +0200

The basic problem is, that parser:foundCharacters: is not called for "id", because id is an ATTRIBUTE, not a NODE VALUE. You need to retrieve the ID from the attributeDict that is passed on parser didStartElement:namespaceURI:qualifiedName:attributes:

But you should also consider using NSXMLDocument and XPath if you are developing for 10.4 and up

Alex

Am 01.04.2009 um 15:01 schrieb developers mac:

Hi there, I have to parse a xml & return the values for val & id (attribute). I have pasted a sample xml below. <response> <field> <values> <val id="AL"> Alabama</val> . . . <val id="WY">Wyoming</ val> </values> </field> <field> <values> <val id="1">Australia</ val> . . . <val id="150">Zambia</val> </values> </field> </response> I am able to retrieve the val(Alabama, Austalia...) & display it in a table view. I need to get the attribute values (AL, 1) - to know which val has been selected. I need to get the attribute value. but i am not sure to get the attribute value according to the click of the val. Can some help me to get through this one please!!!! Also i am able to get the attribute values in didstartelement of xml parser by : tagid = [attributeDict objectForKey:@"id"]; But I am not aware of how to add this value to a array something similar to : - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName: (NSString *)qName attributes:(NSDictionary *)attributeDict{ currentElement = [elementName copy]; if ([elementName isEqualToString:@"val"]) { item = [[NSMutableDictionary alloc] init]; tagid = [attributeDict objectForKey:@"id"]; ( I am getting all the values of attribute here) } } - (void)parser:(NSXMLParser *)parser didEndElement: (NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ if ([elementName isEqualToString:@"val"]) { [item setObject:errorcode forKey:@"val"]; [item setObject:obtID forKey:@"Id"]; [item objectForKey:@"id"]; [stories addObject:[item copy]]; } } - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ if ([currentElement isEqualToString:@"val"]){ [errorcode appendString:string]; } else if ([currentElement isEqualToString:@"Id"]) { obtrowid = string; [obtID appendString:string]; } } I need to retrieve the values of - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath { int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1]; retselval = [[stories objectAtIndex: storyIndex] objectForKey: @"val"]; //retseltag = [dupattr objectForKey:@"id"]; ( This is where I am trying to read the attribute values) } _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >xml parsing (From: developers mac <email@hidden>)

  • Prev by Date: Re: Enable Input method for MS Word Application
  • Next by Date: Re: Crash Reporter shows symbols of stripped app -- it's OK!
  • Previous by thread: Re: xml parsing
  • Next by thread: debugging symbols for universial binary library
  • Index(es):
    • Date
    • Thread