Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8232257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:46:23+00:00 2026-06-07T17:46:23+00:00

So I am trying to write a simple web service that gets the current

  • 0

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. System.out.println 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:

GlobalWeather service = new GlobalWeather();  
GlobalWeatherSoap port = service.getGlobalWeatherSoap();
String data = port.getWeather(city, country);

// this prints the xml response to the console perfectly
System.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);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:46:24+00:00Added an answer on June 7, 2026 at 5:46 pm

    Replace

    xmlReader.parse(data);
    

    with

    InputSource source = new InputSource(new StringReader(data));
    xmlReader.parse(source);
    

    You are accidentally calling the wrong overloading of SAXReader.parse. The version that takes a String expects a URI where it can retrieve the content to parse, not the content itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a simple web service that automagically serializes and deserializes objects
I'm trying to write a simple web service client to interact with my simple
I'm trying to add functionality to a simple web service that will allow me
I'm trying to write a simple load tester for one of our web services,
I am trying to write a very simple web-based email client from scratch with
I'm trying to write a simple curl program to retrieve the web page in
I am trying to write header file. I can write simple headers like add(int
I trying to write a simple function to call unmanaged code from managed code.
I am trying to write some simple code which will read a text file
I'm trying to write a simple code in Java to connect to a memcache

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.