1

I am working on google-maps kml. I have several shapefiles and using QGIS i have converted it to kml files. When i export the kml (save as kml in Qgis). It contains tag like
<SimpleData name="Name">7</SimpleData> but i want tag structure like
<Data name="name"> <value>7</value> </Data> I have export the shape as kml and update the kml change style add BalloonStyle for that i need to modify structure otherwise it will not display info in popup window.Here is the link for rules of tag structure to display popup in google map as per kml extended data

If we use <SimpleData> tag then popup will not display lables in google map

wrong popup
When i change the structure of tags to <Data><Value>it will works gr8 ,Expected popup window is expected popup
I just want to change the tag structure is there automated way to change the tag structure from kml file. like below <simppledata> to <data><value>

<SchemaData schemaUrl="#new_circle">
                <SimpleData name="Name">7</SimpleData>
                <SimpleData name="gid">1</SimpleData>
                <SimpleData name="active_sub">4596</SimpleData>
                <SimpleData name="net_additi">5181</SimpleData>
                <SimpleData name="gross_addi">3917</SimpleData>
                <SimpleData name="churn">4617</SimpleData>
            </SchemaData>` 

to

<Data name="name">
                    <value>7</value>
                </Data>
                <Data name="active_sub">
                    <value>4596</value>
                </Data>
                <Data name="net_additi">
                    <value>5181</value>
                </Data>
                <Data name="gross_additi">
                    <value>3917</value>
                </Data>
                <Data name="churn">
                    <value>4617</value>
                </Data>

here is the sample link in which i have commented the simpledata tag and add manually data and value tag.expected kml output To do it manually will take maximum time because i have thousands of records in other layers.
Please give me any suggestion. Thank you so much in advance.

closed as unclear what you're asking by Devdatta Tengshe, PolyGeo, MappaGnosis, BradHards, whuber Oct 3 '13 at 20:46

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    This question appears to be off-topic because it is not clear what you are doing, and without this supporting information, it will not be useful for future users. – Devdatta Tengshe Oct 3 '13 at 10:05
  • Hello Devdatta Tengshe, I apologise for this. I just want to change the tag structure of kml file because when i use file with tag <simpledata> then on google map popup will not display so i want to update kml tag structure. For that I have created one java class using JDOM library parse file and replace tag. Thanks – Amit Oct 5 '13 at 8:57
  • @PolyGeo et al. The question is quite clear to me -- probably it has been edited since being closed. – Martin F Dec 2 '13 at 23:45
2

I have updated the kml by creating java class using jdom library.For that i need to do some manual task. Remove kml tag and then process file. Here is the class i have created for this

import java.io.File;
import java.io.FileWriter;
import java.util.Iterator;
import java.util.List;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
/**
 * @author amit
 */
public class XMLParser {
    private void getXMLDetails() {
        try {
            SAXBuilder builder = new SAXBuilder();
            File file = new File("sample.xml");
            if (file.exists()) {
                Document document = (Document) builder.build(file);
                Element root = document.getRootElement();
                System.out.println(root.getChildren());
                Element firstTag = root.getChild("Folder");
                //firstTag.getAttribute("tag").setValue("file");
                List rootdata = firstTag.getChildren();
                System.out.println(rootdata);
                for(Iterator<Element> i = rootdata.iterator(); i.hasNext(); ) {
                    Element rootitem =i.next();
                    if(rootitem.getName() =="Placemark"){
                    System.out.println(rootitem.getChildren("ExtendedData"));
                    List listdata = rootitem.getChild("ExtendedData").getChild("SchemaData").getChildren();
                    for(Iterator<Element> j = listdata.iterator(); j.hasNext(); ) {
                        Element item =j.next();
                        System.out.println(item);
                        String gidval = item.getText();
                        Element gid = new Element("value").setText(gidval);
                        item.setText("");
                        item.addContent(gid);
                        System.out.println("test");
                    }
                    }
                }
                String des = new XMLOutputter().outputString(document);
                des = des.replaceAll("SimpleData", "Data");
                des = des.replaceAll("</SchemaData>", "");
                des = des.replaceAll("<SchemaData schemaUrl=\"#new_area\">", "");
                System.out.println("String: " + des.replaceAll("SimpleData", "Data"));
                FileWriter fileWriter = new FileWriter(file);
                fileWriter.write(des);
                fileWriter.close();
            } else {
                System.out.println("File does not exist");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    public static void main(String argS[]) {
        try {
            new XMLParser().getXMLDetails();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}

Here is the link for jarJDOM library


Thanks

Not the answer you're looking for? Browse other questions tagged or ask your own question.