title: Parsing XML in java Malformedurlexception
body: <p>I am trying to parse an xml file but <code>Malformedurlexception</code> occurs. Do you have any idea why it is happening?</p>
  
  <p>note: in first code segment there is a line as comment <code>system.out.println(requestXml)</code> it is working (the xml content is coming right as string) but i want to parse it but parse method is not working.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>String requestXml = "";
  
  try {
      String argUrl = "http://192.168.1.25:3480/data_request?id=sdata&amp;output_format=xml";
  
      URL url = new URL(argUrl);
      URLConnection con = url.openConnection();
      // specify that we will send output and accept input
      con.setDoInput(true);
      con.setDoOutput(true);
  
      con.setConnectTimeout(20000);  // long timeout, but not infinite
      con.setReadTimeout(20000);
  
      con.setUseCaches(false);
      con.setDefaultUseCaches(false);
  
      // tell the web server what we are sending
      con.setRequestProperty("Content-Type", "text/xml");
  
      OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
      writer.write(requestXml);
      writer.flush();
      writer.close();
  
      // reading the response
      InputStreamReader reader = new InputStreamReader(con.getInputStream());
  
      StringBuilder buf = new StringBuilder();
      char[] cbuf = new char[2048];
      int num;
  
      while (-1 != (num = reader.read(cbuf))) {
          buf.append(cbuf, 0, num);
      }
      requestXml = buf.toString();
      xmlParser(requestXml);
  
      //System.out.println(requestXml);
  
  } catch (Throwable t) {
      t.printStackTrace(System.out);
  }
  return requestXml;
  </code></pre>
  
  <p>and xmlParser method is:</p>
  
  <pre><code>protected void xmlParser(String xmlToBeParsed) {
  
      try {
  
          DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
          DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
          Document doc = dBuilder.parse(xmlToBeParsed);
          doc.getDocumentElement().normalize();
          NodeList nodes = doc.getElementsByTagName("devices");
  
          for (int i = 0; i &lt; nodes.getLength(); i++) {
              Node node = nodes.item(i);
  
              if (node.getNodeType() == Node.ELEMENT_NODE) {
                  Element element = (Element) node;
                  System.out.println("Stock Symbol: " + getValue("device name", element));
  
              }
          }
  
      } catch (ParserConfigurationException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (SAXException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  
  private static String getValue(String tag, Element element) {
      NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes();
      Node node = (Node) nodes.item(0);
      return node.getNodeValue();
  }  
  </code></pre>
  
  <p>the log is:</p>
  
  <blockquote>
    <p>04-30 11:55:21.299: W/System.err(826): java.net.MalformedURLException:
    Protocol not found:  04-30 11:55:21.299:
    W/System.err(826): 
    04-30 11:55:21.299: W/System.err(826):  04-30 11:55:21.299:
    W/System.err(826):  04-30
    11:55:21.299: W/System.err(826):  04-30 11:55:21.299:
    W/System.err(826):  04-30 11:55:21.299:
    W/System.err(826):  04-30 11:55:21.299:
    W/System.err(826):  04-30 11:55:21.299: W/System.err(826):
     04-30
    11:55:21.309: W/System.err(826):  04-30 11:55:21.309: W/System.err(826):  04-30
    11:55:21.309: W/System.err(826):  04-30
    11:55:21.309: W/System.err(826):  04-30 11:55:21.309: W/System.err(826):
     04-30 11:55:21.309: W/System.err(826):  04-30
    11:55:21.309: W/System.err(826):  04-30 11:55:21.309: W/System.err(826):  04-30 11:55:21.309:
    W/System.err(826):  04-30 11:55:21.309: W/System.err(826):  04-30 11:55:21.309:
    W/System.err(826): 
    04-30 11:55:21.309: W/System.err(826):  04-30
    11:55:21.309: W/System.err(826):  04-30 11:55:21.309:
    W/System.err(826):    at java.net.URL.(URL.java:178) 04-30
    11:55:21.309: W/System.err(826):  at java.net.URL.(URL.java:127)
    04-30 11:55:21.309: W/System.err(826):    at
    org.apache.harmony.xml.parsers.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:115)
    04-30 11:55:21.319: W/System.err(826):    at
    javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:155)
    04-30 11:55:21.319: W/System.err(826):    at
    com.example.eos.SensorDataConnector.xmlParser(SensorDataConnector.java:93)
    04-30 11:55:21.319: W/System.err(826):    at
    com.example.eos.SensorDataConnector.getXMLData(SensorDataConnector.java:71)
    04-30 11:55:21.319: W/System.err(826):    at
    com.example.eos.EnergyOptimizer$5.onClick(EnergyOptimizer.java:148)
    04-30 11:55:21.319: W/System.err(826):    at
    android.view.View.performClick(View.java:4204) 04-30 11:55:21.319:
    W/System.err(826):    at
    android.view.View$PerformClick.run(View.java:17355) 04-30
    11:55:21.319: W/System.err(826):  at
    android.os.Handler.handleCallback(Handler.java:725) 04-30
    11:55:21.319: W/System.err(826):  at
    android.os.Handler.dispatchMessage(Handler.java:92) 04-30
    11:55:21.319: W/System.err(826):  at
    android.os.Looper.loop(Looper.java:137) 04-30 11:55:21.319:
    W/System.err(826):    at
    android.app.ActivityThread.main(ActivityThread.java:5041) 04-30
    11:55:21.319: W/System.err(826):  at
    java.lang.reflect.Method.invokeNative(Native Method) 04-30
    11:55:21.319: W/System.err(826):  at
    java.lang.reflect.Method.invoke(Method.java:511) 04-30 11:55:21.319:
    W/System.err(826):    at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    04-30 11:55:21.319: W/System.err(826):    at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 04-30
    11:55:21.329: W/System.err(826):  at
    dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>