2017-09-01 4 views
0

GraphMLファイルからデータを抽出しようとしています。ファイルのリンク:https://www.dropbox.com/s/mp5x7ykqabmpzsg/EXEMPLE%202.graphml?dl=0SAX Parser returned emptyメインクラスのリスト

ここでは私のデフォルトのハンドラクラスです:

パブリッククラスMLAnalyserは、3つのリストのサイズは正しかった、このクラスからたDefaultHandler {

public List<List<String>> elementsAttributes = new ArrayList<List<String>>(); 
List<Integer> index_node= new ArrayList<Integer>(); 
List<Integer> target_edge= new ArrayList<Integer>(); 
List<Integer> source_edge= new ArrayList<Integer>(); 

public void startElement(String namespaceURI, String sName, String qName, Attributes attrs) throws SAXException { 
    String eName = sName; 
    if ("".equals(eName)) 
     eName = qName; 
if (eName == "node") { 

    if (attrs != null) { 
     for (int i = 0; i < attrs.getLength(); i++) { 
      String aName = attrs.getLocalName(i); 
      if ("".equals(aName)) { 
      aName = attrs.getQName(i); 
      } 
      System.out.println(" " + aName + "=" + attrs.getValue(i) +"") ; 
      if (aName == "id") { 
       int x = Integer.parseInt(attrs.getValue(i)); 
       index_node.add(x); 
      }  
     } 
    } 
} 
else if (eName == "edge") { 

    if (attrs != null) { 
     //Attributes listing 
     for (int i = 0; i < attrs.getLength(); i++) { 
      String aName = attrs.getLocalName(i); 
      if ("".equals(aName)) { 
       aName = attrs.getQName(i); 
      } 
      System.out.println(attrs.getValue(i)) ; 
      if (aName == "source") 
      { 
       int x = Integer.parseInt(attrs.getValue(i)); 
       source_edge.add(x); 
      } 
      else if (aName == "target") 
      { 
       int x = Integer.parseInt(attrs.getValue(i)); 
       target_edge.add(x); 
      }   

     } 
    } 
} 
System.out.println(index_node.size() + " " + source_edge.size() + " " + target_edge.size()) ; 

}

を拡張しますが、メインクラスでは、MLAnalyserオブジェクトを作成してリストのサイズを印刷すると、それらは空です。

パブリッククラスGraphML_Parser {

public static void main(String[] args) { 
    // TODO Auto-generated method stub 

    MLAnalyser a = new MLAnalyser() ; 

     try{ 

      SAXParserFactory fabrique = SAXParserFactory.newInstance(); 
      SAXParser parseur = fabrique.newSAXParser(); 
      System.out.println(a.index_node.size()); 
      File myfile = new File("D:/EXEMPLE 2.graphml"); 

      DefaultHandler gestionnaire = new MLAnalyser(); 

      parseur.parse(myfile, gestionnaire); 

      for(int i=0; i<a.index_node.size(); i++) 
      { 
       System.out.println("node "+ i + ":"); 
       System.out.println(a.index_node.get(i)); 
      } 
      //GrapheMatrix mat = new GrapheMatrix(a.nodeNum,a.arcNum); 
      //a.create_matrix(); 
     } 

     catch(ParserConfigurationException pce){ 
      System.out.println("Erreur de configuration du parseur"); 
      System.out.println("Lors de l'appel à newSAXParser()"); 
     }catch(SAXException se){ 
      System.out.println("Erreur de parsing"); 
      System.out.println("Lors de l'appel à parse()"); 
     }catch(IOException ioe){ 
      System.out.println("Erreur d'entrée/sortie"); 
      System.out.println("Lors de l'appel à parse()"); 
     } 
} 

}

+0

それは小さなファイルです、なぜあなたはサックスを使用していますか? –

+0

@ vtd-xml-authorそれはちょうど仕事をしたので、コードを実装するのは簡単でした。 – Khaled

答えて

0

溶液 ")(公共ボイドEndDocumentの" と呼び、その中にあなたのコードを書くことでした。