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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:04:03+00:00 2026-06-04T21:04:03+00:00

I am using the following codes to convert XML contents to UTF-8, but they

  • 0

I am using the following codes to convert XML contents to UTF-8, but they are not working properly:

1.

InputStream is = new ByteArrayInputStream(strXMLAlert.getBytes("UTF-8"));
Document doc = db.parse(is); 

2.

InputSource is = new InputSource(new ByteArrayInputStream(strXMLAlert.getBytes()));
is.setCharacterStream(new StringReader(strXMLAlert));
is.setEncoding("UTF-8");
Document doc = db.parse(is);
  • 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-04T21:04:05+00:00Added an answer on June 4, 2026 at 9:04 pm

    We probably need a bit more information to answer the question properly. For example, what problem are you seeing? Which Java version are you running?

    However, expanding your first example to

    DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    String strXMLAlert = "<a>永</a>";
    InputStream is = new ByteArrayInputStream(strXMLAlert.getBytes("UTF-8"));
    Document document = db.parse(is);
    Node item = document.getDocumentElement().getChildNodes().item(0);
    String nodeValue = item.getNodeValue();
    System.out.println(nodeValue);
    

    In this example, there is a Chinese character in the string. It successfully prints out

    永
    

    Your second example should also work, although you are providing the content twice. Either provide it as a set of bytes and provide the encoding, or just provide it as characters (the StringReader) and you don’t need the encoding (since as characters, it’s already been decoded from bytes to characters).

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

Sidebar

Related Questions

i am using following code to convert xml file to datatable but its just
I going to convert text file to XML. I use the following code. But
How can I convert the following XML to an escaped text using XSLT? Source:
I'm using following code but cannot return data from MySQL. This is the output:
I am using following code to create new wifi access point and to connect
I am using following code for add button with image on tool bar, but
I am trying to convert some xml into a json object using PHP. This
i have the following function i wrote to create an XML file using Xerces
I am using JSOUP (java tool for XML files) and I am using following
Hi I'm trying to convert the XML file into associative array by using the

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.