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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:41:20+00:00 2026-05-12T15:41:20+00:00

Even if the question subject seems complicated, the issue is quite simple. I create

  • 0

Even if the question subject seems complicated, the issue is quite simple.

I create an XML file with the following script:

def xmlFile = new File("file-${System.currentTimeMillis()}.xml")
mb = new groovy.xml.StreamingMarkupBuilder()
mb.encoding = "UTF-8"
new FileWriter(xmlFile) << mb.bind {
    mkp.xmlDeclaration()
    out << "\n"
    someMarkup {}
}

Then when I parse this file using code like:

def xml = new XmlSlurper().parse(xmlFile)

I got the following MalformedByteSequenceException exception:

Exception thrown: Invalid byte 2 of
3-byte UTF-8 sequence

And if I convert the file in UTF-8 format (using Notepad++ for instance) then everything is ok.

So, what can I do to save my file in UTF-8 format? Why the code mb.encoding = "UTF-8" does not do it?

Thx

  • 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-12T15:41:20+00:00Added an answer on May 12, 2026 at 3:41 pm

    You need to wrap an output stream writer around a FileOutputStream is utf-8 is not the default charset

    new OutputStreamWriter(new FileOutputStream(exportXmlFile),'utf-8') << mb.bind {
        mkp.xmlDeclaration()
        out << "\n"
        someMarkup {}
    }
    

    I’m not sure what setting mb.encoding does, probably just sets the charset in the xml header

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

Sidebar

Related Questions

The question seems settled, beaten to death even. Smart people have said smart things
complete noob to Haskell here with probably an even noobier question. I'm trying to
I did some googling to try to answer this question but even after that
I'm so new to this that I can't even phrase the question right... Anyway,
Ok, I didn't really know how to even phrase the question, but let me
First of all, I have no idea if the title even reflects my question.
Even before telling my question, will tell you that this is a very vague
Not even sure I'm stating the question correctly. Here's the situation. I have a
I'm not even sure how I should phrase this question. I'm passing some CustomStruct
I am not even sure how to ask this question. I want something that

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.