Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Source Codes E-Books Downloads Contact Us About Us

XML Tutorial
XML Introduction
XML How to use
XML Syntax
XML Elements
XML Attributes
XML Validation
XML Validator
XML Browsers
XML Viewing
XML CSS
XML XSL
XML Data Island
XML Parser
XML in Real Life
XML Namespaces
XML CDATA
XML Encoding
XML Server
XML Application
XML HTTP Request
XML Save Data
XML Behaviors
XML Technologies
XML Editors
XML Summary
XML as Data Source

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


XML Encoding
Previous Next

Choosing the encoding

The characters of XML document can be encoded in different formats. By default XML uses the Unicode (UTF-8 or UTF-16) character set , but other encodings can be used if they are declared in the XML declaration at the beginning of the document.
Due to encoding problem you can get different errors, when you try to load an XML document into Internet Explorer:
"Switch from current encoding to specified encoding not supported."

Such Type of error generate due to inconsistency between the character encoding specified in the XML declaration and the actual character encoding used to serialize the XML document. In XML all characters come from the Universal Character Set (UCS), which always associates a numerical code point with each character. Many algorithms exist for converting code points into a sequence of bytes. A specific character encoding must be used to serialize an XML document. For example, if you type an XML document into notepad and save it, you can choose from one of several supported character encodings including ISO-8859-1, UTF-8, or UTF-16.
According to the XML 1.0 specification, all processors are required to automatically detect and support the UTF-8 and UTF-16 encodings.You don't need an XML declaration if you use one of these two encodings when serializing your documents,


<?xml version="1.0" encoding="UTF-8"?> <!-- optional -->

If you use different encoding other than UTF-8/UTF-16, then you must use an XML declaration to specify the actual encoding used. Without knowing what encoding was actually used how can the processor read the encoding information?
It's easy for processors to auto-detect between UTF-8/UTF-16 with or without an XML declaration by looking for a byte order mark (BOM) required in UTF-16 documents. For all other encodings, you know that the first five characters must be "<?xml". Since a given processor will only support a finite set of encodings, a brute-force algorithm can be used that simply looks at the first few bytes to determine the family of the character encoding used (there are five possible encoding families including UTF-16 big endian, UTF-16 little endian, UCS-4 or other 32-bit encoding, EBCDIC, and everything else). Once the processor detects the encoding family, it can read the rest of the XML declaration (since only a restricted set of characters can be used in the XML declaration), then it can switch to using the specified character encoding within the detected family. If, at this point, the XML declaration tells the processor to switch to an encoding from a completely different family, that error occurs.
So any time you save a document using a specific encoding, then indicate a different encoding in the XML declaration, you will get this error because the encodings must agree.
 




An invalid character was found in text content.

This error message generate when a character in the XML document does not match the encoding attribute and no any encoding attribute was specified. Normally you will get this error message if your XML document contains "foreign" characters and the file was saved with a single-byte encoding editor like notepad.

Windows 2000 notepad without Encoding

Windows 2000 Notepad files may save as Unicode format.
Save the XML file below as Unicode (Country that the document does not contain any encoding attribute):

<?xml version="1.0"?>
<Country>
<from>India</from>
<to>China</to> </Country>

The file above will NOT generate an error in IE 5+, Firefox, or Opera, but it WILL generate an error in Netscape 6.2.

Windows 2000 notepad with Encoding

Windows 2000 notepad files saved as Unicode use "UTF-16" encoding format.

If you add an encoding attribute to XML files saved as Unicode, windows encoding values will generate an error.

The following encoding does not generate error message:

<?xml version="1.0" encoding="windows-1252" ?>
<!-- Edited with XML Spy v2006 (http://www.altova.com) -->
-<Country>
<to>China</to>
<from>India</from>
<heading>remind language</heading>
<body>Norwegian: æøå. French: êèé</body>
</Country>

The following encoding does not generate error message:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!-- Edited with XML Spy v2006 (http://www.altova.com) -->
-<Country>
<to>China</to>
<from>India</from>
<heading>remind language</heading>
<body>Norwegian: æøå. French: êèé</body>
</Country>

The following encoding does not generate error message:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Edited with XML Spy v2006 (http://www.altova.com) -->
-<Country>
<to>China</to>
<from>India</from>
<heading>remind language</heading>
<body>Norwegian: æøå. French: êèé</body>
</Country>

> The following encoding will NOT generate an error in IE 5+, Firefox, or Opera, but in Netscape 6.2 it will generate an error.


<?xml version="1.0" encoding="UTF-16" ?>
<!-- Edited with XML Spy v2006 (http://www.altova.com) -->
-<Country>
<to>China</to>
<from>India</from>
<heading>remind language</heading>
<body>Norwegian: æøå. French: êèé</body>
</Country>


Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previous Next

Keywords: xml document, xml parser, xml schema, xml declaration, xml-encoding, xsl encoding, xml encoding, xml encode, xml unicode encoding, xslt encoding, xml charset, xml base64, xml encoding declaration, xml encoding utf 8, xml encoding iso 8859 1, java xml encoding, xml iso 8859 1, xml character encoding, xml iso 8859, xml encoding iso 8859, xml encoding utf, xml encoding iso, xml encoded, xml version 1.0 encoding utf 8, xml version 1.0 encoding, xml version 1.0 encoding iso 8859 1, javax xml rpc encoding, xml version 1.0 encoding utf 16.


HTML Quizes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
XML Quizes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizes
JavaScript Quiz
VBScript Quiz
AJAX Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizes
ASP Quiz
PHP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
.NET (dotnet) Quizes
Microsoft.Net Quiz
XML Web Services Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
Multimedia Quizes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Web Building  Quizes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Java Quizes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Programming Langauges Quizes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Soft Skills Quizes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz

Privacy Policy
Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.