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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:40:11+00:00 2026-05-24T13:40:11+00:00

I am creating an XML document with DOM and got HTML funny characters like

  • 0

I am creating an XML document with DOM and got HTML funny characters like ä and å from a database that i need to put inside an element. But i can’t get it to work really.

What is the proper way to add CDATA HTML in an element so that my output becomes like this:

<TRANSLATIONS>
    <DENMARK>
        <ERRORADDRESSLINE1REQUIRED><![CDATA[&auml; &aring;]]></ERRORADDRESSLINE1REQUIRED>
    </DENMARK>
</TRANSLATIONS>

using this:

$sData = "<![CDATA[" . $value . "]]>";
$objLabel = $objXmlDoc->createElement($label, $sData);

doesn’t really do the trick
and appending $objXmlDoc->createCDATASection($value) creates an element next to another label and not inside a label.

What do i overlook?

  • 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-24T13:40:11+00:00Added an answer on May 24, 2026 at 1:40 pm

    You have to append the CDATA section to the element you want it in:

    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->appendChild($dom->createElement('translations'))
            ->appendChild($dom->createElement('denmark'))
                ->appendChild($dom->createElement('error'))
                    ->appendChild($dom->createCDataSection('&auml; &aring;'));
    
    $dom->formatOutput = true;
    echo $dom->saveXml();
    

    Output:

    <?xml version="1.0" encoding="utf-8"?>
    <translations>
      <denmark>
        <error><![CDATA[&auml; &aring;]]></error>
      </denmark>
    </translations>
    

    But there should be no need to put ä and å into CDATA sections when you are using UTF-8:

    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->appendChild($dom->createElement('translations'))
            ->appendChild($dom->createElement('denmark'))
                ->appendChild($dom->createElement('error', 'ä and å'));
    
    $dom->formatOutput = true;
    echo $dom->saveXml();
    

    Outputs perfectly valid:

    <?xml version="1.0" encoding="utf-8"?>
    <translations>
      <denmark>
        <error>ä and å</error>
      </denmark>
    </translations>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an XML document from my C# code. I need to add
I'm creating an XML document. I got it to indent using TransformerFactory.setAttribute(indent-number, new Integer(2));
I am creating an XML document on the fly. and I need to know
I am having trouble creating an XML document that contains a default namespace and
I am creating an XML document line by line and need to keep an
I'm creating a browser plugin (bookmarklet) that exacts a large XML document embedded within
I'm creating a plugin/bookmarklet that will take an XML document embedded within the <textarea>
I have an XML document generated from an external application, but that application does
Here is my sample code: from xml.dom.minidom import * def make_xml(): doc = Document()
From the libxml-ruby API docs ( http://libxml.rubyforge.org/rdoc/index.html ), under LibXML::XML::Document, I tried the following:

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.