質問

I have an xml(kml) with this structure:

<Document>
<Folder>
    <Folder>
        <name>A -</name>
        <Placemark>
            <name>Afghanistan</name>
            <description></description>
            <Style>
                <PolyStyle>
                    <color>aaffffff</color>
                    <colorMode>random</colorMode>
                </PolyStyle>
            </Style>
            <Polygon>
                <outerBoundaryIs>
                    <LinearRing>
                        <coordinates> 65.62729644775391,37.33319854736328,0 65.64692687988283,37.45888137817383,0</coordinates>
                    </LinearRing>
                </outerBoundaryIs>
            </Polygon>
        </Placemark>
        <Placemark>
            <name>Albania</name>

I am trying to get the name of each country and their coordinates and save them on arrays. This one gives me "Placemark" for elementValue and "null" for urlValue.

if ([elementName isEqualToString:@"Placemark"]){
    NSString *urlValue=[attributeDict valueForKey:@"name"];

    NSLog(@"I just found a start tag for %@ %@",elementName,urlValue);

}

Should I use any other delegate? What I am doing wrong here?

役に立ちましたか?

解決

<name> isn't an attribute of <Placemark>, it's a child element. You need to set a flag or some such method and wait for the parser to call the delegate again via parser:didStartElement:... with "name" as the elementName. You can turn the flag off again when you get to parser:didEndElement:... on "Placemark" in preparation for the next iteration.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top