MalformedURLException when parsing web service response

velvetntassien

New Member
So I am trying to write a simple web service that gets the current weather. With the following code the web service method can be called and the returned XML data can be printed to the console.However, when I try to parse this method response I get MalformedURLException. I can see the XML I want to parse in the error. So I tried saving the response to a file to parse it that way:When I try saving the web response to a file I get all Chinese letters. \[code\]System.out.println\[/code\] prints out the XML perfectly to the console like I need it to be in the file.I am a total newb so please excuse me if I am missing something very simple. I would like to do this without having to save the file locally, but whatever works is good here.My problem lies somewhere in this code:\[code\]GlobalWeather service = new GlobalWeather(); GlobalWeatherSoap port = service.getGlobalWeatherSoap();String data = http://stackoverflow.com/questions/11461738/port.getWeather(city, country);// this prints the xml response to the console perfectlySystem.out.println(data);SAXParserFactory spf = SAXParserFactory.newInstance();spf.setNamespaceAware(true);SAXParser saxParser = spf.newSAXParser();XMLReader xmlReader = saxParser.getXMLReader();xmlReader.setContentHandler(new WeatherApp());// this gives MalformedURLexception when set up this way.// this gives the correct output when passed a locally stored XML file// I have omitted my SAX methods and my weather class that holds the data// but all work fine when using a local XML file on my machine.xmlReader.parse(data);\[/code\]
 
Back
Top