1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| public class Example {
Element racine =new Element("source");
Document document=new Document(racine);
Element racine2;
Document document2;
List liste;
public void parcourire() throws JDOMException, IOException,FileNotFoundException{
String textfile="source.xml";
SAXBuilder sxb = new SAXBuilder();
document2 = sxb.build(new File(textfile));
racine2=document2.getRootElement();
liste=racine2.getChildren();
}
public void inser( )throws JDOMException, IOException{
//ici je parcourt mon fichier xml et retourne son compte dans ma liste.
parcourire();
//je verifie si mon document n'a qu'un seul Element c-a-d le rootElement
if(document.getContent().size()==1){
// si oui alors alors j'ajoute à ma racine ma collection d'element
racine.addContent(liste);
} |
Partager