This article will teach you about
commenting and learning how to write text which you
want to go unparsed in XML.
Commenting
Sometimes, your code can get long
and complicated, and you may forget what part of your
code does. Commeting is done in a programming language
if you want to write notes in your file to remember
what a part of your file does. It is also a good idea
to comment because it lets other people who are viewing
your code know what you are doing. You can insert comments
anywhere inside your code, and XML will completely
ignore the text you have inside the comment. To write
a comment in XML, you have to write:
<!-- This part of the
script gives information -->
|
Anything inside the <!-- -->
tag will be ignored by the XML language. It can be
as long as you'd like, spanning as many lines as
you'd like. Get in the habit of using comments; they
always come back to help you later on.
Having Unparsed Text
So what if you want to write a bit
of HTML or other programming language code directly
inside the XML file? Well, that's a problem because
everything's new to XML. However, the clever people
who made XML devised an ingenious way, called CDATA,
to place code in XML. Just like commenting, everything
inside these tags is sent unparsed by XML. However,
insted of it being ignored by the parser, it is just
copied directly on to the HTML page. For example, if
you wanted to display a picture and write the code
for it in HTML inside an XML pag, you could write:
<![CDATA[
<img src="main.jpg" height="23"
width="34" alt="Main" />
]]>
|
To have XML not parse a specific blob
of data, you start by writing <![CDATA[ , place
the text you don't want parsed in the middle, and end
it by the ]]> . You can write any code you want
in any language, and you don't have to follow any XML
rules inside the CDATA. The one rule to follow is that
you cannot have another ]]> inside the CDATA, so
no nested CDATAs are allowed.
|