title: How to Read XML Document from URL
body: <p>Hi I am working with Document Class. When I am reading File from local system it is working and when I want to read the file and try to load the XML Document from some URL its not working.</p>
  
  <pre><code>private static Document loadTestDocument(String fileLocation) throws Exception {
      DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      factory.setNamespaceAware(true);
      DocumentBuilder db = factory.newDocumentBuilder();
      File file = new File(fileLocation);
      System.out.println(db.parse(file).toString());
      return  db.parse(file);
  }
  </code></pre>
  
  <p>So this method is returning Document if I have a service which returns xml and I want to consume it how can I do this I want to directly load from the service GET url. </p>
  
  <p>I tried with this but its not working </p>
  
  <pre><code>File file = new File("http://someservice/getdata");
  </code></pre>
  
  <p>Error: File not found
  Then I tried to load it from Input Stream it also not working from me. </p>
  
  <pre><code>InputStream input = new URL("http://someurl:32643/api/values").openStream();
  </code></pre>
  
  <p>Error: </p>
  
  <pre><code>[Fatal Error] :1:1: Content is not allowed in prolog.
  </code></pre>
  
  <p>Now how can I achieve this any help will be appreciated I want to load the data received from the service and want to return a Document of that as I am returning in my method.</p>