2012-02-20 17 views
1

理由はわかりませんが、Log.i(TAG、 "found:" + found);私のXMLの "found"要素に対してnullを返します。これはストリームに入ります。私はデバッグして、XMLのルート要素が読み込まれているように見えますが、そのルート要素の要素は読み取れません。 urlStringも正しいです。ドキュメントはエラーと例外なしで解析されます。しかし、この行ではAndroidでのXMLストリームの解析

NodeList nl = docEle.getElementsByTagName("found"); 
     found = nl.item(0).getNodeValue(); 

が見つかりました。これは、XMLと私のurlStringは

protected Void doInBackground(String... urls) { 

     String urlString = urls[0]; 
     URL documentUrl = null; 
     InputStream stream = null; 
     URLConnection conn = null; 
     DocumentBuilder builder = null; 
     Document document = null; 
     try { 
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 
      builder = factory.newDocumentBuilder(); 

      documentUrl = new URL(urlString); 
      conn = documentUrl.openConnection(); 
      stream = conn.getInputStream(); 
      document = builder.parse(stream); 
     } 
     catch (IOException e) { 
      Error = e.getMessage(); 
      Log.i(TAG, "Exception!", e); 
     } 
     catch (SAXException e) { 
      Error = e.getMessage(); 
      Log.i(TAG, "Exception!", e); 
     } 
     catch (ParserConfigurationException e) { 
      Error = e.getMessage(); 
      Log.i(TAG, "Exception!", e); 
     } 
     finally 
     { 
      if (stream != null) 
      { 
       try { 
        stream.close(); 
       } catch (IOException e) { 
        Error = e.getMessage(); 
        Log.i(TAG, "Exception!", e); 
       } 
      } 
     } 

     /*NodeList nodes = document.getElementsByTagName("found"); 
     for (int i = 0; i < nodes.getLength(); i++) { 
      found = nodes.item(i).getNodeValue(); 
      //System.out.println(found); 
      Log.i(TAG, "found: "+found); 
     }*/ 

     //get the root element 
     Element docEle = document.getDocumentElement(); 
     NodeList nl = docEle.getElementsByTagName("found"); 
     found = nl.item(0).getNodeValue(); 
     Log.i(TAG, "found: "+found); 

     return null; 
    } 

です::これは、メソッドの完全なコードですhttp://basa.med-info.ru/xse/index.php?query=%E3%F0%E8%EF%EF&nres=20

答えて

2

使用に等しくなければなりませんが見つかりました:

found = nl.item(0).getFirstChild().getNodeValue(); 
+0

おかげで、その問題だった – wzbozon