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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T18:18:06+00:00 2026-06-03T18:18:06+00:00

I need to create an XML file using DOM under Eclipse (for Java) and

  • 0

I need to create an XML file using DOM under Eclipse (for Java) and using the following code :

        // write the content into xml file
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        DOMSource source = new DOMSource(doc);
        StreamResult result = new StreamResult(new File("output.xml"));  
        transformer.transform(source, result);

My XML’s first line is :

<?xml version="1.0" encoding="UTF-8"?>

and not :

<?xml version="1.0"?>

My questions are :

  1. What is the difference between those two declarations ?

  2. How can I generate the XML file using the header : <?xml version="1.0"?>

Regards

  • 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-03T18:18:07+00:00Added an answer on June 3, 2026 at 6:18 pm

    In the modern world, text files have an “encoding”, which defines how characters are represented in the file. You won’t see this if your file contains ONLY plain ASCII characters (0x01 thru 0x7f) but if you need to represent anything else, such as symbols or accented characters, then a consumer of the file needs to know how those characters are encoded.

    There are several different ways to encode extended characters, the most common ones being ISO-8859-x (where x depends on the language) and Unicode, which assigns a unique number to every possible character. The ISO code pages use the range 0x80 thru 0xFF for extended characters. UTF-8 is a system of representing Unicode characters (aka “code points”) of arbitrary length in multiple 8-bit bytes. The same extended character (for example e-circumflex) will have different representations in different encodings.

    The serializer you used is configured to output UTF-8 encoding. A consumer of that file must be aware that UTF-8 encoding was used, or risk mangling the data. You have probably seen web pages containing black-diamond characters, or text where things like apostrophes or other special characters are replaced with 2 weird characters. These are symptoms of incompatible encoding/decoding.

    There is probably a way to force the serializer to omit the encoding declaration, but if you do the consumer of the file may not be able to decode it correctly, since it will have to guess about the encoding.

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

Sidebar

Related Questions

I need to parse a xml file using JAVA and have to create a
I need to create a new XML file and write that to my server.
I need to create application log file using Linq-To-Xml. I would like to lock
I am in need of using classic ASP to create an XML file from
I need to create an XML schema definition (XSD) that describes Java objects. I
I need to create program that creates a XML schema like below using System.Xml.XmlSchema
I have parsed an xml file using the digester parser , now i need
I need to create HarrCascade XML file to use it with OpenCV for tracking
I've got some code to convert a large (many gigabytes) XML file into another
I need to write model data ( CharField s only) to an XML file

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.