0

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?

BlackM
  • 3,927
  • 8
  • 39
  • 69

1 Answers1

1

<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.

rsswtmr
  • 1,776
  • 5
  • 16
  • 26
  • and how I get the value of name? – BlackM Feb 10 '13 at 22:43
  • `parser:foundCharacters:` will be called at least once, perhaps several times. You accumulate characters until you hit the end of the current element, in this case, `name`. You might find it easier to use a third party library like [TBXML](http://www.tbxml.co.uk/TBXML/TBXML_Free.html) which is designed for this sort of parsing. – rsswtmr Feb 10 '13 at 22:46
  • So I will use a global variable as flag and read all characters when the elementName=name? – BlackM Feb 10 '13 at 22:47