Remplir un tableau

linaing Messages postés 27 Date d'inscription lundi 5 avril 2010 Statut Membre Dernière intervention 26 mai 2011 - 16 juin 2010 à 23:37
edouard333 Messages postés 62 Date d'inscription samedi 23 décembre 2000 Statut Membre Dernière intervention 18 décembre 2011 - 28 juin 2010 à 22:19
salut

je veux parcourir un fichier xml avec des espaces de noms en java ,j' ai utilisé SAX ,voila mon code:

private void openfile(File fichier) {
chemin.setText("Le chemin: " + fichier);
SAXParser p=null;
try {
p=SAXParserFactory.newInstance().newSAXParser();
p.getXMLReader().setFeature("http://xml.org/sax/features/namespaces",true );
}
catch (ParserConfigurationException pce) {
System.err.println("Impossible de créer le parser SAX");
System.err.println(pce);
System.exit(1);
}catch (SAXException saxe) {
System.err.println("Erreur SAX.");
System.err.println(saxe);
System.exit(1);
}
try{
p.parse(fichier, new MonGestionnaire());
}catch (SAXException saxe){
System.err.println("Erreur SAX.");
System.err.println(saxe);
System.exit(1);
}catch(IOException ioe){
System.err.println("Erreur de lecture du fichier.");
System.err.println(ioe);
System.exit(1);
}
}


import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;


public class MonGestionnaire extends DefaultHandler {

public void startElement(String nameSpaceURI, String localName, String rawName, Attributes attributs) throws SAXException {
String nom = attributs.getValue(0);
if( localName.equals("Module_enseignement")){
System.out.println(""+ nom);
}

if( localName.equals("aborde")){
System.out.println(" "+ nom);
}
}// startElement


}


une partie de mon fichier xml:
<?xml version="1.0" encoding="ISO-8859-1" ?> 
  <!DOCTYPE rdf:RDF (View Source for full doctype...)> 
- <rdf:RDF xmlns="http://www.owl-ontologies.com/Ontology1265893389.owl#" xml:base="http://www.owl-ontologies.com/Ontology1265893389.owl" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:owl="http://www.w3.org/2002/07/owl#">
  <owl:Ontology rdf:about="" /> 
- <owl:ObjectProperty rdf:ID="aborde">
  <rdfs:domain rdf:resource="#Module_enseignement" /> 
  <rdfs:range rdf:resource="#Notion" /> 
  </owl:ObjectProperty>
- <Notion rdf:ID="attribut">
   
   
  </Notion>
- <Module_enseignement rdf:ID="Base-donnee">
   
   
   
   
   
   
   
   
   
   
   

.................
.................

<Module_enseignement rdf:ID="Reseau" /> 
  <Module_enseignement rdf:ID="Systeme-exploitation" /> 
  </rdf:RDF>


ça m'affiche :
Base-donnee
#attribut
#FN2
#BCNF
#normalisation
#FN1
#Formes_normales
#modele_relationnel
#cle
#relation
#conception_base_donnee
#FN3
Reseau
Systeme-exploitation

exactement ce que je veux,mais je ne peux pas stocker ces infos dans un tableau???!!quelqu'un a une idée!!!!!!!!!!c'est urgent

merci d'avance.

1 réponse

edouard333 Messages postés 62 Date d'inscription samedi 23 décembre 2000 Statut Membre Dernière intervention 18 décembre 2011 1
28 juin 2010 à 22:19
Tu n'as cas donner les valeurs de 'nom' à un tableau:
nom_du_tableau.append(nom);
Et voila :)
Ou:

public class Fenetre extends JFrame{

  JTextArea txt;
  JScrollPane barre;

  public Fenetre(){
  setSize(400,300);
    txt= new JTextArea(14,33);
         txt.setEditable(false);
      
         add(barre= new JScrollPane(txt, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
         barre.setAutoscrolls(true);
      
      //Le texte de 'txt':
         txt.append(nom);
  }

}
0
Rejoignez-nous