Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes XML and Related Technologies and the fly likes What is teh difference between comments and header in xml file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "What is teh difference between comments and header in xml file" Watch "What is teh difference between comments and header in xml file" New topic
Author

What is teh difference between comments and header in xml file

Hemal Mehta
Ranch Hand

Joined: Nov 16, 2000
Posts: 101
What is teh difference between
<?xmlversion="1.0"?> and <!--hello-->
Karthik Guru
Ranch Hand

Joined: Mar 06, 2001
Posts: 1209
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.
Ajith Kallambella
Sheriff

Joined: Mar 17, 2000
Posts: 5782
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.

HTH,

------------------
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).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is teh difference between comments and header in xml file