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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:38:07+00:00 2026-05-23T13:38:07+00:00

edit how to add a encoding in the xml "header" now the "header" looks

  • 0

edit

how to add a encoding in the xml "header"

now the "header" looks like this:

<?xml version="1.0"?>

how can you when using SimpleXML in PHP add a encoding in the "header"?

my xml class:

class XML {
    private $root = '<response />';
    
    function __construct($root=null){
        $this->root = new SimpleXMLElement($root ? $root:$this->root);
    }
    
    function encode($arr, $node=null){
        $node = $node == null ? $this->root:$node;
        foreach($arr as $key => $value){
            if(is_array($value)){
                $this->encode($value, $node->addChild($key));
            }
            else{
                $node->addChild($key, $value);
            }
        }
    }
    
    function output(){
        return $this->root->asXML();
    }
}
  • 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-23T13:38:08+00:00Added an answer on May 23, 2026 at 1:38 pm

    Well my Danish isn’t perfect (or present at all for that matter). However, I know as a fact XML nodes cannot begin with a number. And since the error seems to be complaining abou the well-formedness of the XML data, I’d say it’s because of the <0></0> node.

    You can try to change:

    private $root = '<response />';
    

    To something like this:

    private $root = '<?xml version="1.0" encoding="utf-8" ?><response />';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this xml result from calling the page getRout.php <?xml version=1.0 encoding=UTF-8?> <kml
I'm using PHP xmlreader to validate and parse xml data. This xml is validated
I am using C#.net I want to add custom edit/delete buttons to my GridView1
When you edit a simple page in the design view, you can add an
Edit: This question was written in 2008, which was like 3 internet ages ago.
I am trying to add document to the index using c# (xml) but I
I have the following XML: <?xml version=1.0 encoding=UTF-8?> <details> ... <address1>Test&amp;Address</address1> ... </details> When
During development I've seen xml read errors like this more than once: TestData.ReadFromXml: xml
Lets say I have the following XML file: <?xml version=1.0 encoding=utf-8?> <Customers xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=Customer.xsd>
I wrote a small PHP script to edit the site news XML file. I

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.