Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why XML encoding required?

Tags:

xml

I have a basic understanding of XML. My question is why is it necessary to mention the encoding used at the beginning of a XML document and why encoding is required ?

like image 632
AmritaS Avatar asked Sep 15 '25 09:09

AmritaS


2 Answers

It is not required, although usually you may want to include it:

In the absence of external character encoding information (such as MIME headers), parsed entities which are stored in an encoding other than UTF-8 or UTF-16 must begin with a text declaration (see 4.3.1 The Text Declaration) containing an encoding declaration.

So, for example, when transferring XML via HTTP, XML parser might use the value from Content-Type header like this:

Content-Type application/xml; charset=UTF-8

But once this document is stored locally, it would not contain this information - thus it seems like a good idea to include encoding into the declaration part of XML document.

like image 126
kamituel Avatar answered Sep 18 '25 08:09

kamituel


why is it necessary to mention the encoding used at the beginning of a XML document

It isn't. There are defaults. (UTF-8 and UTF-16, which can be reliably distinguished between programatically)

and why encoding is required

Computers only understand binary. Encoding is the process of representing letters, numbers, etc in binary so it can be processed by a computer. Different encodings store the characters in different ways.

like image 33
Quentin Avatar answered Sep 18 '25 08:09

Quentin