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 6930811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:29:46+00:00 2026-05-27T11:29:46+00:00

I want to parse an XML file from URL using JDOM. But when trying

  • 0

I want to parse an XML file from URL using JDOM. But when trying this:

SAXBuilder builder = new SAXBuilder();
builder.build(aUrl);

I get this exception:

Invalid byte 1 of 1-byte UTF-8 sequence.

I thought this might be the BOM issue. So I checked the source and saw the BOM in the beginning of the file. I tried reading from URL using aUrl.openStream() and removing the BOM with Commons IO BOMInputStream. But to my surprise it didn’t detect any BOM.
I tried reading from the stream and writing to a local file and parse the local file. I set all the encodings for InputStreamReader and OutputStreamWriter to UTF8 but when I opened the file it had crazy characters.

I thought the problem is with the source URL encoding. But when I open the URL in browser and save the XML in a file and read that file through the process I described above, everything works fine.

I appreciate any help on the possible cause of this issue.

  • 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-05-27T11:29:46+00:00Added an answer on May 27, 2026 at 11:29 am

    That HTTP server is sending the content in GZIPped form (Content-Encoding: gzip; see http://en.wikipedia.org/wiki/HTTP_compression if you don’t know what that means), so you need to wrap aUrl.openStream() in a GZIPInputStream that will decompress it for you. For example:

    builder.build(new GZIPInputStream(aUrl.openStream()));
    

    Edited to add, based on the follow-up comment: If you don’t know in advance whether the URL will be GZIPped, you can write something like this:

    private InputStream openStream(final URL url) throws IOException
    {
        final URLConnection cxn = url.openConnection();
        final String contentEncoding = cxn.getContentEncoding();
        if(contentEncoding == null)
            return cxn.getInputStream();
        else if(contentEncoding.equalsIgnoreCase("gzip")
                   || contentEncoding.equalsIgnoreCase("x-gzip"))
            return new GZIPInputStream(cxn.getInputStream());
        else
            throw new IOException("Unexpected content-encoding: " + contentEncoding);
    }
    

    (warning: not tested) and then use:

    builder.build(openStream(aUrl.openStream()));
    

    . This is basically equivalent to the above — aUrl.openStream() is explicitly documented to be a shorthand for aUrl.openConnection().getInputStream() — except that it examines the Content-Encoding header before deciding whether to wrap the stream in a GZIPInputStream.

    See the documentation for java.net.URLConnection.

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

Sidebar

Related Questions

I am trying to parse an XML file from a URL by taking all
I am new to jquery. I am trying to parse xml string using jquery.
I want to read an XML file from an URL and I want to
I want show weather information from xml to this URL: http://www.google.com/ig/api?weather=roma&hl=it using this script:
I want to parse a large XML file and I have two options: Perl
-<stat> <visitor>4</visitor> <uniqueVisitor>2</uniqueVisitor> <order>41</order> <revenue>20658</revenue> <conversionRate>48</conversionRate> <newProduct>25</newProduct> <outOfStockProduct>11</outOfStockProduct> </stat> From this xml i want
In my application I am loading xml from url in order to parse it.
I'm trying to parse Reddit's XML file with javascript and im having trouble retrieving
i'm having some troubles trying to parse an XML file and display the results
I have an XML file which I want to convert into JSON file using

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.