title: Parsing XML stream in Android
body: <p>I don't know why, but Log.i(TAG, "found: "+found); returns null for "found" element in my XML, that I get in a stream. I have debugged and it seems that my root element of XML is read, but elements of that root element are not. urlString is also correct. document is parsed without any errors and exceptions. But in this lines </p>
  
  <pre><code>NodeList nl = docEle.getElementsByTagName("found");
          found = nl.item(0).getNodeValue();
  </code></pre>
  
  <p>found is null. This is the full code of a method: </p>
  
  <pre><code>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 &lt; 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;
      }
  </code></pre>
  
  <p>This is my urlString with XML: <a href="http://basa.med-info.ru/xse/index.php?query=%E3%F0%E8%EF%EF&amp;nres=20" rel="nofollow">http://basa.med-info.ru/xse/index.php?query=%E3%F0%E8%EF%EF&amp;nres=20</a></p>
  
  <p>found must be equal to 20. </p>