NSXMLParser: no analiza los atributos con el mismo valor de nodo

I am parsing the below xml in iOS.

<START>
    <ROW>
     <COLUMN NAME="NAME">John Smith</COLUMN>
    </ROW>
    <ROW>
     <COLUMN NAME="NAME">Steve Irwin</COLUMN>   
    </ROW>
  </START>

I wrote the below code. I need John Smith in the string "amaps.Name" but for me the string is coming as "NAME". Can anyone help me to parse this xml

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

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

        //Initialize the book.
        MapDetails* amaps = [[MapDetails alloc] init];
        amaps.NAME = [attributeDict objectForKey:@"NAME"];
        NSLog(@"Reading id value :%@", amaps.NAME);
    }

    //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:@"RESULTS"])
        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:@"ROW"])
        return;

    if([elementName isEqualToString:@"COLUMN"]) {
        [appDelegate.maps addObject:amaps];
        //[amaps release];
        //amaps = nil;
    }
    else 
        [amaps setValue:currentElementValue forKey:[elementName lowercaseString]];

    [currentElementValue release];
    currentElementValue = nil;
}

preguntado el 31 de julio de 12 a las 10:07

1 Respuestas

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

         strVal=string;

 }

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

    if([elementName isEqualToString:@"RESULTS"])
        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:@"ROW"])
    {
     }


    if([elementName isEqualToString:@"COLUMN"]) 
    {
         amaps.Name=strVal;
    }
    else 
        [amaps setValue:currentElementValue forKey:[elementName lowercaseString]];

    [currentElementValue release];
    currentElementValue = nil;
}

esto debería ser un trabajo.

Respondido 31 Jul 12, 11:07

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.