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
  


Attributes must have quoted values page 7 of 10


There are two rules for attributes in XML documents:

  • Attributes must have values
  • Those values must be enclosed within quotation marks

Compare the two examples below. The markup at the top is legal in HTML, but not in XML. To do the equivalent in XML, you have to give the attribute a value, and you have to enclose it in quotes.


<!-- NOT legal XML markup -->
<ol compact>

<!-- legal XML markup -->
<ol compact="yes">
          

You can use either single or double quotes, just as long as you're consistent.

If the value of the attribute contains a single or double quote, you can use the other kind of quote to surround the value (as in name="Doug's car"), or use the entities &quot; for a double quote and &apos; for a single quote. An entity is a symbol, such as &quot;, that the XML parser replaces with other text, such as ".


Main menuSection menuFeedbackPreviousNext
Privacy Legal Contact