iphonensxmlparser

How to user NSXMLParser if nodes are not sequential in iphone programming?


I have following link, returning XML as from following link

    http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=24.827774,67.034367    //This is URLString link

     NSXMLParser *xmlParser=[[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:
                                                             [NSString stringWithFormat:@"%@",URLString]]]; 
    [xmlParser setDelegate:self];
    [xmlParser parse];



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



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

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

I want to save only values of "city" "weather" "temp_f" and "temp_c" so for displaying on labels;

I am really get confuse always about NSXMLParser parsing, I would be thankful if someone will define in good words, so that I get proper understanding of NSXMLParser

Thank you in Advance


Solution

  • In your didEndElement delegate method check for the elementName.

    if (elementName isEqualtoString:@"city"])
    // Save the element which is currently holding the value from the `foundCharacters` delegate method into your variable.
    

    You can do the same for the other values you want.