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 92 93 94 95
| void AjoutBaliseAntécédent( int x)
{
try {
/************compter nbre de mots avant selection dans le jtexterea1***********/
String AvantSelect=jTextArea1.getText(0,x);
StringTokenizer ST= new StringTokenizer(AvantSelect);
int m=ST.countTokens();
System.out.print("m="+m);
/*******************compter nbre de mots sélectionnés*************************/
String motselected= jTextArea1.getSelectedText();
StringTokenizer ST1= new StringTokenizer(motselected);
int m1=ST1.countTokens();
System.out.print("m1="+m1);
/***************Copie du fichier XML******************/
DocumentBuilderFactory factor =DocumentBuilderFactory.newInstance();
DocumentBuilder builde;
builde = factor.newDocumentBuilder();
Document docum;
docum = builde.parse(new File(nomfich));
Element racine = docum.getDocumentElement(); Node Texte=racine;
Element monElement =docum.createElement("EXP");
Attr monAttribut=docum.createAttribute("id");
monAttribut.setValue("0");
monElement.setAttributeNode(monAttribut);
NodeList list=Texte.getChildNodes();
NodeList list1;
NodeList list2;
NodeList list3;
Node elem;
int n=0;
if (list.getLength()!=0)
{
for (int i=0;i<list.getLength();i++)
{
elem= list.item(i);
list1=elem.getChildNodes();
if (list1.getLength()!=0)
{
for (int j=0;j<list1.getLength();j++)
{
Node element1= list1.item(j);
list2=element1.getChildNodes();
if (list2.getLength()!=0)
{
for (int k=0;k<list2.getLength();k++)
{
Node element2= list2.item(k);
list3=element2.getChildNodes();
if (list3.getLength()!=0)
for (int z=0;z<list3.getLength();z++)
{
Node element3= list3.item(z);
n=n+1;
if(n==m+1)
{
Node e=docum.insertBefore(monElement, element3);
for(int h=1;h<=m1;h++) {
monElement.appendChild(list3.item(z++));
}
}
}
}
}
Affichage( "\n ");
}
}
}
}
}catch (Exception ep){System.out.println("errrrrrrreur!!!!!!!"+ ep);}
} |