Sams Teach Yourself XML in 21 Days
- Table of Contents
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Introduction
- Part I: At a Glance
- Day 1. Welcome to XML
- Day 2. Creating XML Documents
- Day 3. Creating Well-Formed XML Documents
- Day 4. Creating Valid XML Documents: DTDs
- Declaring Attributes in DTDs
- Day 6. Creating Valid XML Documents: XML Schemas
- Day 7. Creating Types in XML Schemas
- Part I. In Review
- Day 8. Formatting XML by Using Cascading Style Sheets
- Day 9. Formatting XML by Using XSLT
- Day 10. Working with XSL Formatting Objects
- Part II. In Review
- Part III: At a Glance
- Day 11. Extending HTML with XHTML
- Day 12. Putting XHTML to Work
- Day 13. Creating Graphics and Multimedia: SVG and SMIL
- Day 14. Handling XLinks, XPointers, and XForms
- Part III. In Review
- Part IV: At a Glance
- Day 15. Using JavaScript and XML
- Day 16. Using Java and .NET: DOM
- Day 17. Using Java and .NET: SAX
- Day 18. Working with SOAP and RDF
- Part IV. In Review
- Part V: At a Glance
- Day 19. Handling XML Data Binding
- Day 20. Working with XML and Databases
- Day 21. Handling XML in .NET
- Part V. In Review
- Appendix A. Quiz Answers
Creating an XML Declaration
XML declarations tell XML processors what version of XML you're using, what character encoding the document is written in, and so on. According to W3C, all XML documents should start with an XML declaration, which should be the first line in an XML document. You can also have XML document fragments in some cases, which don't start with an XML declaration, although such fragments are losing support. Here's a sample XML declaration:
<?xml version = "1.0" standalone="yes" encoding="UTF-8"?>
The XML declaration uses the <?xml?> element. In earlier drafts of XML, it was <?XML?>, but was made lowercase in the final recommendation—it's an error to use uppercase. There are three possible attributes you can use in the XML declaration:
- version— The XML version; currently, only 1.0 or 1.1 is possible here, and most XML processors do not support 1.1 yet. This attribute is required if you use an XML declaration.
- encoding— The language encoding for the document. As discussed earlier today, the default here is UTF-8. You can also use Unicode, UCS, and many other character sets, such as ISO character sets. This attribute is optional.
- standalone— Set to "yes" if the document does not refer to any external documents or entities, "no" otherwise. This attribute is optional.
Creating XML Comments | Next Section

Account Sign In
View your cart