2012-05-03 6 views
-1

xmlファイルを解析すると、すべてのデータが解析されますが、このデータをテキストビューで設定する方法はわかりません。私はそのサックスの解析後にテキストボックスにデータを設定する方法

public class GtuItemXMLHandler extends DefaultHandler { 

    Gtudownload gtudownload; 
    Questionpaper questionpaper; 

    // Show me the XML. 
    private String currentString = ""; 
    private String charactersString = ""; 
    private Branch branch; 
    private Year year; 
    private Semester semester; 
    private int branchCount = 0; 
    private int yearCount = 0; 
    private int semesterCount = 0; 

// private ArrayList<Gtudownload> itemsList = new ArrayList<Gtudownload>(); 
// 
// public ArrayList<Gtudownload> getItemsList() { 
//  return itemsList; 
// } 

    public Gtudownload getGtudownload(){ 
     return this.gtudownload; 
    } 
    public Questionpaper getQuestionpaper() 
    { 
     return this.questionpaper; 
    } 


    // Called when tag starts 
    @Override 
    public void startElement(String uri, String localName, String qName, 
      Attributes attributes) throws SAXException { 
     Log.i("GTU ", localName); 
     if (localName.equalsIgnoreCase("Gtudownload")) { 
      gtudownload = new Gtudownload(); 
      currentString = "Gtudownload"; 

     } else if (localName.equalsIgnoreCase("Questionpaper")) { 
      gtudownload.setQuestionpaper(new Questionpaper()); 
      gtudownload.getQuestionpaper().setBranchList(new ArrayList<Branch>()); 
      currentString = "Questionpaper"; 
     } else if (localName.equalsIgnoreCase("Branch")) { 
      branch = new Branch(); 
      gtudownload.getQuestionpaper().getBranchList().add(branch); 
      gtudownload.getQuestionpaper().getBranchList().get(branchCount).setYearList(new ArrayList<Year>()); 
      currentString = "Branch"; 
      Log.i("Branch", attributes.getValue("value")); 
      branch.setValue(attributes.getValue("value")); 
     } else if (localName.equalsIgnoreCase("Year")) { 
      year = new Year(); 
      gtudownload.getQuestionpaper().getBranchList().get(branchCount).getYearList().add(year); 
      gtudownload.getQuestionpaper().getBranchList().get(branchCount).getYearList().get(yearCount).setSemesterList(new ArrayList<Semester>()); 
      currentString = "Year"; 
      Log.i("Year ", attributes.getValue("value")); 
      year.setValue(attributes.getValue("value")); 
     } else if (localName.equalsIgnoreCase("semester")) { 
      semester = new Semester();   
      currentString = "semester"; 
      Log.i("Semester ", attributes.getValue("value")); 
      semester.setValue(attributes.getValue("value")); 
      gtudownload.getQuestionpaper().getBranchList().get(branchCount).getYearList().get(yearCount).getSemesterList().add(semester); 
     } else if (localName.equalsIgnoreCase("url")){ 
      currentString = "url"; 
     } 

    } 

    // Called when tag closing 
    @Override 
    public void endElement(String uri, String localName, String qName) 
      throws SAXException { 
     if(localName.equalsIgnoreCase("Questionpaper")){ 
      branchCount=0;   
     }else if(localName.equalsIgnoreCase("Branch")){ 
      yearCount = 0; 
      branchCount++; 
     }else if(localName.equalsIgnoreCase("Year")){ 
      semesterCount = 0; 
      yearCount++; 
     }else if(localName.equalsIgnoreCase("semester")){ 
      semesterCount++; 
     }else if(localName.equalsIgnoreCase("url")){ 
      gtudownload.getQuestionpaper().getBranchList().get(branchCount).getYearList().get(yearCount).getSemesterList().get(semesterCount).setUrl(charactersString); 
      Log.i("URL", charactersString); 
     } 
     currentString = ""; 
     charactersString= ""; 

    } 

    // Called to get tag characters 
    @Override 
    public void characters(char[] ch, int start, int length) 
      throws SAXException { 
     charactersString = new String(ch, start, length); 
     charactersString = charactersString.trim(); 
    } 

} 

についていくつかのアイデアを与える、これは私の活動であり、どのように私はGoogleで、このために非常に多くの例を買ってあげるのTextView

public class GtudldActivity extends Activity { 
    /** Called when the activity is first created. */ 
    private TextView xmlOutput; 
    TextView example[]; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     xmlOutput = (TextView) findViewById(R.id.xmlOutput); 

     Gtudownload gtudownload = parseXML(); 

    } 

    private Gtudownload parseXML() { 

     Gtudownload gtudownload = null; 

     try { 

      Log.w("AndroidParseXMLActivity", "Start"); 
      /** Handling XML */ 
      SAXParserFactory spf = SAXParserFactory.newInstance(); 
      SAXParser sp = spf.newSAXParser();  
      XMLReader xr = sp.getXMLReader(); 

      GtuItemXMLHandler myXMLHandler = new GtuItemXMLHandler(); 
      xr.setContentHandler(myXMLHandler); 
      InputSource is = new InputSource(getResources().openRawResource(R.raw.mgtu)); 


      gtudownload = myXMLHandler.getGtudownload(); 

      Log.i("Data",gtudownload+""); 
      xr.parse(is); 

     } catch (Exception e) { 
      Log.w("AndroidParseXMLActivity", e); 
     } 

     //xmlOutput.setText(gtudownload.toString()); 

     return gtudownload; 

    } 
} 
+0

あなたの活動の中で価値を得ていますか? – Nitin

答えて

-1

には、この解析データを設定することができます。私はあなたの1つを見せています。ただ試してみてくださいthis

私はあなたを助けてくれることを願っています。あなたが疑問があれば、ここに投稿してください

+0

私は異なるデータ構造を持っています。 –

+0

だからこそ私はあなたにgoogleで検索するよう指示しています。あなたは間違いなくあなたのコードに一致する例を見つけるでしょう。他のコードはここに投稿してください –

関連する問題