Skip to main content
IBM  
Shop Support Downloads
IBM Home Products Consulting Industries News About IBM
IBM developerWorks : XML : Education - Tutorials
Introduction to XML
ZIPPDF (letter)PDF (A4)e-mail
Main menuSection menuFeedbackPreviousNext
3. XML document rules
  


Other things in XML documents page 9 of 10


There are a few other things you might find in an XML document:

  • Comments: Comments can appear anywhere in the document; they can even appear before or after the root element. A comment begins with <!-- and ends with -->. A comment can't contain a double hyphen (--) except at the end; with that exception, a comment can contain anything. Most importantly, any markup inside a comment is ignored; if you want to remove a large section of an XML document, simply wrap that section in a comment. (To restore the commented-out section, simply remove the comment tags.) Here's some markup that contains a comment:

<!-- Here's a PI for Cocoon: -->
<?cocoon-process type="sql"?>
          
  • Processing instructions: A processing instruction is markup intended for a particular piece of code. In the example above, there's a processing instruction (sometimes called a PI) for Cocoon, an XML processing framework from the Apache Software Foundation. When Cocoon is processing an XML document, it looks for processing instructions that begin with cocoon-process, then processes the XML document accordingly. In this example, the type="sql" attribute tells Cocoon that the XML document contains a SQL statement.

<!-- Here's an entity: -->
<!ENTITY dw "developerWorks">
          
  • Entities: The example above defines an entity for the document. Anywhere the XML processor finds the string &dw;, it replaces the entity with the string developerWorks. The XML spec also defines five entities you can use in place of various special characters. The entities are:
    • &lt; for the less-than sign
    • &gt; for the greater-than sign
    • &quot; for a double-quote
    • &apos; for a single quote (or apostrophe)
    • &amp; for an ampersand.

Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact