Show Menu

XML 1.0 Cheat Sheet by

XML Quick Reference v1.1


XML stands for eXtensible Markup Language.
XML documents are struct­ured, tagged documents composed of elements, attrib­utes, processing instru­ctions, namespace declar­ations, comments, and text.


<root />
<ro­ot>­child data</­roo­t>
There can be exactly one root element of an XML document. (The document element)
Elements have a name and may also have children; Child data may be text, elements, attrib­utes, or other types of XML struct­ures.
Element names are case-s­ens­itive
Elements must be correctly nested:
Element names must start with a letter or unders­core. The following characters may contain letters, digits, periods, hyphens, unders­cores, or colons.


Elements can be annotated with attrib­utes. Attributes cannot exist in a serialized document without a parent element.
Attributes are name/value pairs that are separated by an equals sign, with a value surrounded by matching sing or double quotes.
The attributes for an element are serialized within the start tag of an element.
<User login=­"­J.S­mit­h" enroll­ed=­"­201­4-1­2-1­4" />
<User enroll­ed=­"­201­4-1­2-1­4">J.Sm­ith­</U­ser>
Attribute names follow the same rules as element names.


<pr­efi­x:l­oca­lname xmlns:­pre­fix­="UR­I" />
<ta­gname xmlns=­"­URI­" />
Namespaces resolve ambiguity when tag names collide.
Namespace declar­ations appear in an element start tag and are typically mapped to shorter prefix.
Namespace declar­ations are scoped to the element they are defined in, and all descen­dants thereof.
All elements in an XML document are QNames (qualified names); A QName is a local name with an optional prefix.
Both the prefix and the local name are NCNames (No-colon names).
The namespace of an element with a given prefix is the namespace specified by the in-scope namespace declar­ation for that prefix. (May be overridden)
The namespace of un-pre­fixed elements is the default namespace.
Attribute names are QNames; unprefixed attributes are in no namespace, even if a default namespace is in scope.


<!-- Commented text -->
Comments can contain spaces, text, elements, and line breaks, and can therefore span multiple lines of XML
You may not use a double hyphen (
) within a comment itself; therefore, you cannot nest comments

Character References

Character references can only be used for element and attribute content


<?xml versio­n="1.0"?>
<?t­arget data?>
Only processing instru­ctions and comments may appear before the document lement
The processing instru­ction target
is reserved
No processing instru­ction may start with the string
or any recapi­tal­ization thereof

Predefined Entities

There are five predefined entities used in the XML markup which must be escaped in order to appear in XML content
You may not use (<) or (&) anywhere in your XML document, except to begin a tag or an entity, respec­tively


<![­CDA­TA[­Almost any content here]]>
Use a
section to include content that you do not want the XML parser to interpret
CDATA stands for (unparsed) character data, as opposed to PCDATA (parsed character data)
You may not nest CDATA sections
CDATA sections may be used anywhere withing the root element of an XML document
If you need to include the string
in the CDATA text, and you are not closing the CDATA section, the closing > must be written as &gt;


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Web Programming Cheat Sheet
          Web Programming Exam Cheat Sheet

          More Cheat Sheets by nqramjets