Originally posted by Hemal Mehta: What is teh difference between <?xmlversion="1.0"?> and <!--hello-->
i did'nt follow your question properly. But, i guess an xml document need not have a header but if u have one it s'd be right at the top. I read somewhere that the parser uses the inital characters to make some guess of the encoding used. Comments can be inserted anywhere..it is used as usual for describing something to the guy who w'd read the xml document. it's just like u comment ur code. karthik.
What you called the "header" is technically known as the Prolog. Here is an extract from the XML spec from W3C
2.8 Prolog and Document Type Declaration [Definition:] XML documents may, and should, begin with an XML declaration which specifies the version of XML being used. For example, the following is a complete XML document, well-formed but not valid: <?xml version="1.0"?> <greeting>Hello, world!</greeting>
and so is this: <greeting>Hello, world!</greeting>
The version number "1.0" should be used to indicate conformance to this version of this specification; it is an error for a document to use the value "1.0" if it does not conform to this version of this specification. It is the intent of the XML working group to give later versions of this specification numbers other than "1.0", but this intent does not indicate a commitment to produce any future versions of XML, nor if any are produced, to use any particular numbering scheme. Since future versions are not ruled out, this construct is provided as a means to allow the possibility of automatic version recognition, should it become necessary. Processors may signal an error if they receive documents labeled with versions they do not support.
Clearly, the Prolog declaration is optional. However, when present, parsers may look closely at what has been declared in the Prolog for various verification purposes. Comments on the other hand serve the same purpose as they do in the context of programs. They just add to clarity/readability of the document but they are not( and should not be ) used to represent data/markup. W3C does not require the parsers to read and make the comments available to XML applications, eventhough many of today's parsers do read comment blocks. Here is an extract from XML spec about Comments -
[Definition:] Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string "--" (double-hyphen) must not occur within comments.
------------------ Ajith Kallambella M. Sun Certified Programmer for the Java�2 Platform. IBM Certified Developer - XML and Related Technologies, V1.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
subject: What is teh difference between comments and header in xml file