Lire fichier xml iso ou utf sous java

bonjour,
apres avoir lu un fichier xml avec le code ci-dessous:

import java.io.File;
import java.io.IOException;

import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
import org.jdom2.input.SAXBuilder;

public class NewClass {

public static void main(String[] args) {
SAXBuilder builder=new SAXBuilder();

try {
Document readDoc=builder.build(new File("Exercice.xml"));
Element root=readDoc.getRootElement();
for(Element cur:root.getChildren("etudiant")){

System.out.println("Les noms sont: ------- "+cur.getAttributeValue("classe"));
}

} catch (JDOMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}}
------------------------
j'ai eu un problème lorsque je voulais changé la version du xml, parce que je dois mettre la version : <?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE Pige SYSTEM "Pige.dtd"> a la place de <?xml version="1.0" encoding="UTF-8"?>.
l'éditeur m'affiche un message d'erreur "org.jdom2.input.JDOMParseException: Error on line 2 of document file:/C:/Users/Admin/Documents/NetBeansProjects/proj/Exercice.xml: The processing instruction target matching "[xX][mM][lL]" is not allowed.
"
voici mon fichier xml :
<?xml version="1.0" encoding="UTF-8"?>
<personnes>
<etudiant classe="P2">
<nom>CynO</nom>
</etudiant>
<etudiant classe="P1">
<nom>Superwoman</nom>
</etudiant>
<etudiant classe="P1">
<nom>Don Corleone</nom>
</etudiant>
</personnes>

je serais reconnaissant si vous pouvez m'aider
merci d'avance
bien à vous:D

1 réponse

  • Votes
  • Date
  • Date décroissante
  1. welcome ,
    peut ouvrir le fiche avec netpad ou bien change l'extentio de fiche par le ronemer
    1. oui j'ai renomer le fichier en modifiant la version xml mais il m'affiche le message d'erreur :
      org.jdom2.input.JDOMParseException: Error on line 2 of document file:/C:/Users/Admin/Documents/NetBeansProjects/proj/Exercice.xml: The processing instruction target matching "[xX][mM][lL]" is not allowed.

      merci de votre aide.