Comments
March 29, 1999
Not only will you sometimes want to include tags in your XML
document that you want the XML processor to ignore (display
as character data), but sometimes you will want to include character
data in your document that you want the XML processor to ignore
(not display at all).
This type of text is
called COMMENT text.
You will be familiar with comments from HTML. In HTML, you
specified comments using the <!-- and --> syntax. Well,
I have some good news. In XML, comments are done in just the
same way! So the following would be a valid XML comment:
<!-- Begin the Names -->
<NAME>Jim Nelson</NAME>
<NAME>Jim Sanger</NAME>
<NAME>Les Moore</NAME>
<!-- End the names -->
When using comments in your XML documents, however, you should
keep in mind a couple of rules.
First, you should never have "-" or "--" within the text of
your comment as it might be confusing to the XML processor.
Second, never place a comment within a tag. Thus, the
following code would be poorly-formed XML:
<NAME <!--The name --> >Peter Williams</NAME>
Likewise, never place a comment inside of an entity declaration
and never place a comment before the XML declaration that must
always be the first line in any XML document.
|
Comments can be used to comment out tag sets. Thus, in the
following case, all the names will be ignored except for
Barbara Tropp.
<!-- don't show these
<NAME>Kieron Drake</NAME>
<NAME>Bob Woodley</NAME>
<NAME>Roger Kaplan</NAME>
-->
<NAME>Barbara Tropp</NAME>
However, if you do comment out blocks of tags, make sure that
the remaining XML is well-formed.
|
Comments cannot be nested, so if you use
a comment to block out a bunch of tags, there can be no comments
within the
block.
CDATA
Introduction to XML For Web Developers | Table of Contents
Processing Instructions
|