XML — Encoding
Encoding Declaration
<?xml version="1.0" encoding="UTF-8"?>
Common Encodings
| Encoding | Description |
|---|---|
| UTF-8 | Unicode, most common |
| UTF-16 | Unicode 16-bit |
| ISO-8859-1 | Western European |
| ASCII | Basic English |
| US-ASCII | ASCII subset |
Unicode Characters
<text>Hello, world! 日本語のテスト</text>
Character Entities
<text>Less than: < Greater than: > Ampersand: &</text>
Numeric References
<text>A A Both represent "A"</text>
BOM (Byte Order Mark)
<!-- UTF-8 BOM is optional -->
<?xml version="1.0" encoding="UTF-8"?>
Encoding Best Practices
- Always declare encoding
- Use UTF-8 when possible
- Avoid non-ASCII in element names
- Use entities for special characters
Mini Practice
- Create XML with UTF-8 encoding
- Include special characters
- Use numeric character references
- Test with different encodings
Up Next
Continue with Validation — validating XML documents.
Related Topics
Frequently Asked Questions about Encoding
What is Encoding in XML?
Encoding is a fundamental concept in XML. This lesson explains it step by step with clear examples, making it easy for beginners to understand.
How do I learn Encoding?
Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Encoding.
Why is Encoding important in XML?
Encoding is essential for XML development. Understanding this concept will help you write better code and solve real-world problems more effectively.