title: Reading XML file from URL in java
body: <p>I need to read the XML returned by API called in form of an URL, and convert in document format for further processing.</p>
  
  <p>The URL is of form <code>http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryClass=person&amp;MaxHits=1&amp;QueryString=Adam%20Sandler</code>. I referred the answer at <a href="https://stackoverflow.com/questions/2310139/how-to-read-xml-response-from-a-url-in-java">read xml from url</a> and used the following code. But the statement printed is <strong>"doc [#document: null]"</strong>. What mistake am I doing?</p>
  
  <pre><code>    String pre_apiURL = "http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryClass=person&amp;MaxHits=1&amp;QueryString=";        
      String apiURL = pre_apiURL + celeb + "";
      apiURL = apiURL.replaceAll(" ","%20");
      System.out.println("url "+apiURL);
      URL url = new URL(apiURL);
  
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(url.openStream());
  
      System.out.println("doc " + doc.toString());
  </code></pre>