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

  • Home
  • SEARCH
  • 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 1018181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:49:14+00:00 2026-05-16T10:49:14+00:00

When I try to write UTF-8 Strings into an XML file using DOMDocument it

  • 0

When I try to write UTF-8 Strings into an XML file using DOMDocument it actually writes the hexadecimal notation of the string instead of the string itself.

for example:

ירושלים

instead of:

ירושלים

Any ideas how to resolve the 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-16T10:49:15+00:00Added an answer on May 16, 2026 at 10:49 am

    Ok, here you go:

    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->appendChild($dom->createElement('root'));
    $dom->documentElement->appendChild(new DOMText('ירושלים'));
    echo $dom->saveXml();
    

    will work fine, because in this case, the document you constructed will retain the encoding specified as the second argument:

    <?xml version="1.0" encoding="utf-8"?>
    <root>ירושלים</root>
    

    However, once you load XML into a Document that does not specify an encoding, you will lose anything you declared in the constructor, which means:

    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->loadXml('<root/>'); // missing prolog
    $dom->documentElement->appendChild(new DOMText('ירושלים'));
    echo $dom->saveXml();
    

    will not have an encoding of utf-8:

    <?xml version="1.0"?>
    <root>&#x5D9;&#x5E8;&#x5D5;&#x5E9;&#x5DC;&#x5D9;&#x5DD;</root>
    

    So if you loadXML something, make sure it is

    $dom = new DOMDocument();
    $dom->loadXml('<?xml version="1.0" encoding="utf-8"?><root/>');
    $dom->documentElement->appendChild(new DOMText('ירושלים'));
    echo $dom->saveXml();
    

    and it will work as expected.

    As an alternative, you can also specify the encoding after loading the document.

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

Sidebar

Ask A Question

Stats

  • Questions 509k
  • Answers 509k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I think the way to do this would be in… May 16, 2026 at 4:45 pm
  • Editorial Team
    Editorial Team added an answer I don't know any more than you about SPARC's future.… May 16, 2026 at 4:45 pm
  • Editorial Team
    Editorial Team added an answer OK, here goes... You have points A, B, and C,… May 16, 2026 at 4:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to write down a UTF-8 string (Vietnamese) into C# Console but no
I write my debug information to a file using a separate thread. During startup,
I have a Java Client which sends UTF-8 strings to a C# TCP-Server, I'm
Use Case I need to package up our kml which is in a String
In Java, I am trying to parse an HTML file that contains complex text
Okay, so I'm going to take the off chance that someone here has used
I have an instance of Apache Tomcat 6.x running, and I want it to
I was trying to download and parse a webpage with foreign (Chinese) characters. I'm
I have a struts2 web application which accepts both POST and GET requests in
I use jdbcRealm for security in my glassfish v3.0.1 b22. It is set up

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.