title: Converting NodeList to String in Java
body: <p>I'm trying to convert NodeList to String so I can manipulate it in whichever way I want, but I can't seem to find an answer online. </p>
  
  <p>I've tried storing the NodeList in a Node array, but all the data printed out would be null.</p>
  
  <p><strong>TextingXPath.java</strong></p>
  
  <pre><code>import java.io.IOException;
  
  public class TestingXPath {
  
  
  static Node[] copy;
  static int length;
  
  public static void main(String[] args) throws SAXException, IOException,
          ParserConfigurationException {
  
      URL obj = new URL("http://jbossews-ashton.rhcloud.com/testXML.jsp");
      HttpURLConnection con = (HttpURLConnection) obj.openConnection();
      con.setRequestMethod("GET");
      int responseCode = con.getResponseCode();
  
      if (responseCode == 200) {
  
          DocumentBuilderFactory domFactory = DocumentBuilderFactory
                  .newInstance();
          try {
              DocumentBuilder builder = domFactory.newDocumentBuilder();
              Document dDoc = builder.parse(con.getInputStream());
  
              XPath xPath = XPathFactory.newInstance().newXPath();
  
              Node node = (Node) xPath.evaluate(
                      "/HDB/Resident[@Name='Batman ']/Preference", dDoc,
                      XPathConstants.NODE);
              if (null != node) {
                  NodeList nodeList = node.getChildNodes();
                  for (int i = 0; null != nodeList
                          &amp;&amp; i &lt; nodeList.getLength(); i++) {
                      Node nod = nodeList.item(i);
                      if (nod.getNodeType() == Node.ELEMENT_NODE)
                          {
  
                          ...
  
                          }
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
  }
  </code></pre>
  
  <p>}</p>