0

I am Trying To Use NSXMLParser to parse an xml file using cocoa which goes like this..

<UserDetails>
<Name>John Doe</Name>
<UserName>jdoe</UserName>
<Password>supersecretpass</Password>
</UserDetails>

Now i am using the method as follows:

-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:    (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    NSLog(@"MEthod came here");
    if ([elementName isEqualToString:@"Name"]) {

        NSLog(@"Name :");
    }
}

I want to retrieve the values contained in the elementName tag. How do i do it..The method is being called but i am unable to retrieve the value contained within the tag values of XML.

proctr
  • 452
  • 4
  • 15
  • You should have a look at this question: http://stackoverflow.com/questions/4181690/choosing-the-right-ios-xml-parser – Kasper K. Oct 06 '11 at 11:56
  • i did..but the question is about which parser to select..i am working with NSXMLParser..i need to know how to retrieve the values from XML Elements.. – proctr Oct 06 '11 at 12:17

1 Answers1

1

You can access the value enclosed within tags by intelligently using this delegate method ;):

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

This link can prove to be useful - Handling XML Elements and Attributes

Devarshi
  • 16,440
  • 13
  • 72
  • 125