Erreur lors de la conversion Excel vers kml
Salut,
J'essaie de faire un fonction pour convertir un fichier Excel vers kml mais mon problème lorsque j'introduis le fichier kml dans google earth, il n'y a pas affichage des points sur la carte.
J'essaie d'ajouter :
Code:
1 2
| Attribute a=new Attribute("xmlns","http://www.opengis.net/kml/2.2");
racine.setAttribute("xmlns", "http://www.opengis.net/kml/2.2"); |
Mais Eclipse affiche l'erreur suivante :
Citation:
Exception in thread "main" org.jdom.IllegalNameException: The name "xmlns" is not legal for JDOM/XML attributes: An Attribute name may not be "xmlns"; use the Namespace class to manage namespaces.)
Quelqu'un aurait-il une idée ? Merci d'avance pour votre aide.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
| package pfe;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.XmlSchema;
import javax.xml.bind.annotation.XmlRootElement;
import java.io.*;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import java.io.*;
//JDOM
import org.jdom.transform.*;
import org.jdom.output.*;
//TrAX
import javax.xml.transform.*;
import javax.xml.transform.stream.StreamSource;
import org.jdom.*;
import org.jdom.output.*;
public class Toutexceltokml {
//Nous allons commencer notre arborescence en créant la racine XML
//qui sera ici "personnes".
static Element racine = new Element("kml");
//On crée un nouveau Document JDOM basé sur la racine que l'on vient de créer
static org.jdom.Document document = new Document(racine);
// static org.jdom.Document document1 = new Document(racine2);
public static void main(String[] args) throws BiffException, IOException
{
// Attribute a=new Attribute("xmlns","http://www.opengis.net/kml/2.2");
//racine.setAttribute("xmlns", "http://www.opengis.net/kml/2.2");
Element cellule1 = new Element("Placemark");
racine.addContent(cellule1);
Workbook workBook = null;
FileInputStream filein = null;
String nameFile = "d:\\path.xls";
filein = new FileInputStream(nameFile);
workBook = Workbook.getWorkbook(filein);
// static Element racine = new Element("");
//static org.jdom.Document document = new Document(racine);
Sheet onglet1 = workBook.getSheet(0);
for (int i = 0; i < onglet1.getRows(); i++) {
for(int j =0;j<onglet1.getColumns();j++)
{ Cell cell= (Cell) onglet1.getCell(j,i);
Cell cell1= (Cell) onglet1.getCell(j,0);
System.out.println(cell1.getContents().toString());
Element cellule = new Element( cell1.getContents().toString());
cellule.setText(cell.getContents().toString());
cellule1.addContent(cellule);}
//Les deux méthodes qui suivent seront définies plus loin dans l'article
affiche();
enregistre("d:\\Toutexceltokml.kml");
}}
// TODO Auto-generated method stub
private static void affiche() {
try
{
//On utilise ici un affichage classique avec getPrettyFormat()
XMLOutputter sortie newXMLOutputter(Format.getPrettyFormat());
sortie.output(document, System.out);
}
catch (java.io.IOException e){}
}
static void enregistre(String fichier)
{
tr {
XMLOutputter sortie = newXMLOutputter(Format.getPrettyFormat());
sortie.output(document, new FileOutputStream(fichier));
}
catch (java.io.IOException e){}
}
} |