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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:25:40+00:00 2026-06-05T02:25:40+00:00

If I build an XML from line to line, I can set the encoding,

  • 0

If I build an XML from line to line, I can set the encoding, but when I load it from file, I cannot add the encoding. See:

procedure TForm1.Button1Click(Sender: TObject);
var
    x : TXMLDocument;
    s : string;
    w : WIdeString;
begin
    s := '<?xml version="1.0"?><a><b/></a>';
    x := TXMLDocument.Create(Self);
    x.XML.Text := s;
    x.Active := True;
    x.Encoding := 'UTF-8';
    x.DocumentElement.childNodes['b'].attributes['x'] := '1';
    x.SaveToXML(w);
    ShowMessage(w);
end;

Interesting that the “encoding” part is missing from the result!

How do I make the result contain the XML encoding?

  • 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-05T02:25:41+00:00Added an answer on June 5, 2026 at 2:25 am

    You’re saving your XML to a WideString. A WideString is, by definition, UTF16-encoded, so there’s no point whatsoever in specifying another encoding. IIRC, you can specify an encoding="UTF-16", which won’t be removed, since that’s what it is.

    You can, however, specify a different encoding if you consequently save the XML document to a stream.

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

Sidebar

Related Questions

I have the following defined in a file called build-dependencies.xml <?xml version=1.0 encoding=UTF-8?> <project
Imagine this as the code from build.xml: <project name=test project> <target name=first> <echo>first</echo> </target>
I have a master build file which is calling other build.xml files of different
I'm trying to better integrate Eclipse with my build.xml. My build file calls GNU
Do you have some predefined set of targets which all build.xml files you create
I'm running ant and added the below to build.xml but I'm getting:\ build.xml:51: Element
So I set up a new project into Eclipse and created a build.xml that
In my build.xml, Eclipse indicates there is an error, but running the Ant task
I'm having trouble using Simple Xml Serializer to build a Message from a complex
MyBatis documentation shows a way to build a SqlSessionFactory through XML configuration file or

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.