DevYudh
DevYudh

Reputation: 2737

Android - KML Parser using DOM Parser

i've a problem here. i wanna parsing a KML document from google maps. i'd successfuly to parsing the nodes which stores a coordinate.

but i wanna parse the node as childnodes here is the KML documents.

<Placemark>
<name>Head north on Jalan Kebagusan Raya toward Jalan Anggrek</name>
<description><![CDATA[go 850&#160;m]]></description>
<address>Jalan Kebagusan Raya</address>
...
</Placemark

to parse it i used this code,

NodeList nlPlace = doc.getElementsByTagName("Placemark");
        for(int p = 0; p < nlPlace.getLength(); p++){
            Node rootPlace = nlPlace.item(p);
            NodeList itemPlace = rootPlace.getChildNodes();
            for(int y = 0; y < itemPlace.getLength(); y++){
                Node placeStringNode = itemPlace.item(y);
                NodeList place = placeStringNode.getChildNodes();
                //valueName = nameList.item(0).getNodeValue().toString() + "+";
                pathName.add(place.item(0).getNodeValue());
            }
        }

desk.setText("");
        for (int j = 0; j < strPlace.length; j++){
            desk.append("Deskripsi:\n" + strPlace[j] + "\n");
        }

but when i tried in a real device/emulator, i got something i dont want to. this is the screenshot from my real device enter image description here

from the scrshot, i just want to grab the "Head northeast on Jalan Darmo Kali toward Jalan Darmoerjo 4" informations. just it.

can u help me to solve my problems?

thanks in advance, and sorry for my english, thanks :)

Upvotes: 1

Views: 605

Answers (1)

techi.services
techi.services

Reputation: 8533

Something like the following should do what you want.

NodeList nlPlace = doc.getElementsByTagName("Placemark");
for(int p = 0; p < nlPlace.getLength(); p++){
    Element place = (Element)nlPlace.item(p);
    Element name = (Element)place.getElementsByTagName("name");

    //.....
    }
}

Upvotes: 1

Related Questions