Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

XML declaration: required or not? Concrete Examples?

 
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?
 
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
 
Author
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
 
I can't take it! You are too smart for me! Here is the tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic