• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What is teh difference between comments and header in xml file

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is teh difference between
<?xmlversion="1.0"?> and <!--hello-->
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

reply
    Bookmark Topic Watch Topic
  • New Topic