2011-06-07 32 views
1

這是我用於android 2.3的代碼。它用來正常工作。 不過不要沒有,爲什麼它似乎並沒有在Android 3.0的documentbuilderfactory不工作在android 3.0

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
     try 
     { 

      try 
      { 
      while(this.xml.available()>0) 
      Log.e("content", ""+this.xml.read()); 
      } 
      catch (Exception e) { 
       // TODO: handle exception 
       Log.e("error", "while reading the file"); 
      } 
      this.xml.reset(); 

      DocumentBuilder builder = factory.newDocumentBuilder(); 
      Document dom = builder.parse(this.xml); 
      Element root = dom.getDocumentElement(); 
      Log.d(TAG, "have root?"+dom.getLocalName());; 
      Log.d(TAG, "have root?"+dom.getInputEncoding());; 
      Log.d(TAG, "have root?"+dom.getNodeValue());; 
} 
     catch (Exception e) 
     { 
      Log.e(TAG, e.getMessage(), e); 
     } 
     //Log.d(TAG, "Exit: parse"); 
     return stores; 
    } 

工作的腸子同時顯示在數字文件內容。 但是當我得到dom。*我得到null爲什麼是這樣?

任何暗示?

+0

root.getTagName()返回正確的頭標籤..但是當我嘗試節點列表項= root.getElementsByTagName( 「somenode」);我總是得到零 – 2011-06-07 10:08:55

回答

0

現在看起來元素被訪問的方式有點不同。

對於其他人來說,看看寫作的新方法。

感謝

1

請勿使用Element root = dom.getDocumentElement();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
DocumentBuilder builder = factory.newDocumentBuilder(); 
Document dom = builder.parse(stream); 

NodeList nodeResponse = dom.getElementsByTagName("rootelement");