Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML declaration: required or not? Concrete Examples?

 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While reading I observed contradictory statements abt XML declaration <?xml version='1.0'?>:
1)the XML declaration "should always be included"
and
2)"while it is not required".
Is the omission an error? Why should it be included?
XML processors do not give any error without it, i.e. does not require it at all. Can you give me example when and for what it is so essential?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The specification says http://www.w3.org/TR/2000/REC-xml-20001006#dt-xmldecl that "XML documents should begin with an XML declaration which specifies the version of XML being used"
The xml declaration can help the parser to determine which character encoding is being used -
http://www.w3.org/TR/2000/REC-xml-20001006#sec-guessing
Cheers,
Dan
 
Scott Duffy
Author
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The official rule, I believe, is:
The XML declaration is optional, but highly recommended. If an XML document includes the XML declaration, it must be the very first line of the xml document, no comments, spaces, PIs, or anything before it.
The <?xml ...?> declaration is special in that it can only include the three attibutes, version, encoding and standalone, in THAT order. And version is mandatory, and must be set to "1.0". No other values for version are permitted.
Hope that helps...
Scott Duffy
MCSD, SCJP, and taking IBM XML tomorrow
 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan and Scott,
thanks a lot
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic