0
<events>
        <status>OK</status>
        <name>20121203</name>
        <descripcion></descripcion>
        <url_IOS></url_IOS>

        <printers>
            <coordenadas_LAT>40.44702054203392</coordenadas_LAT>
            <coordenadas_LON>-3.703991174697876</coordenadas_LON>
        </printers>

        <printers>
            <coordenadas_LAT>40.448416693004596</coordenadas_LAT>
            <coordenadas_LON>-3.7036800384521484</coordenadas_LON>
        </printers>

    </events>

==== 大家好,我有这个 XML,我正在解析:

 - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
    {
        // the start of a 'booth' element is been encountered
        if([elementName isEqualToString:@"events"])
        {
            self.tmpEvent = [[PublicPrivateEvent alloc] init];
        }

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

        currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    }
    - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
    {
       if ([elementName isEqualToString:@"coordenadas_LAT"]) {

                tmpEvent.latitude =currentElementValue;
        }
        if([elementName isEqualToString:@"coordenadas_LON"])
        {
            tmpEvent.longtitude = currentElementValue ;

        }
        if([elementName isEqualToString:@"description"])
        {
            tmpEvent.description = currentElementValue;

        }

        if([elementName isEqualToString:@"url_IOS"])
        {
            tmpEvent.imgurlios6 = currentElementValue;

        }

        if([elementName isEqualToString:@"printers"])
        {

            [printers addObject:tmpEvent];
             currentElementValue = nil;
        }
        if([elementName isEqualToString:@"status"])
        {
            [events addObject:tmpEvent];
            currentElementValue = nil;
        }

    }

=== 我有 2 台打印机,但是当我试图获得这 2 个坐标时,我只获得了最后一个坐标两次?问题是什么。我哪里错了你能帮帮我吗?提前致谢..

4

1 回答 1

0

是的。我曾是。下面是我的解决方案。希望有所帮助。

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

    // the start of a 'booth' element is been encountered
    if([elementName isEqualToString:@"evento"])
    {
        self.tmpEvent = [[PublicPrivateEvent alloc] init];
        self.dictionaryPrinters = [[NSMutableDictionary alloc] init];

    }

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

    currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
   if ([elementName isEqualToString:@"coordenadas_LAT"]) {


       [self.dictionaryPrinters setValue:currentElementValue forKey:@"coordenadas_LAT"];
       tmpEvent.latitude =currentElementValue;


    }
    if([elementName isEqualToString:@"coordenadas_LON"])
    {
        [self.dictionaryPrinters setValue:currentElementValue forKey:@"coordenadas_LON"];
        tmpEvent.longtitude = currentElementValue ;


    }
    if([elementName isEqualToString:@"description"])
    {
        tmpEvent.description = currentElementValue;

    }
    if([elementName isEqualToString:@"url_imagen_evento_LDPI"])
    {
        tmpEvent.imgurlldp = currentElementValue;

    }
    if([elementName isEqualToString:@"nombre"])
    {
        tmpEvent.name = currentElementValue;

    }
    if([elementName isEqualToString:@"url_imagen_evento_MDPI"])
    {
        tmpEvent.imgurlmdp = currentElementValue;

    }

    if([elementName isEqualToString:@"url_imagen_evento_HDPI"])
    {
        tmpEvent.imgurlhdp = currentElementValue;

    }
    if([elementName isEqualToString:@"url_imagen_evento_XHDPI"])
    {
        tmpEvent.imgurlxhdp = currentElementValue;

    }
    if([elementName isEqualToString:@"url_imagen_evento_IOS5"])
    {
        tmpEvent.imgurlios5 = currentElementValue;

    }
    if([elementName isEqualToString:@"url_imagen_evento_IOS6"])
    {
        tmpEvent.imgurlios6 = currentElementValue;
    }

    if([elementName isEqualToString:@"impresora"])
    {
        [printers addObject:[self.dictionaryPrinters copy]];

    }
    if([elementName isEqualToString:@"status"])
    {
        [events addObject:tmpEvent];
        currentElementValue = nil;
    }
于 2013-08-27T22:06:28.763 回答