XML Basics Cheat Sheet
A foundational reference for XML document structure, elements, attributes, namespaces, and validation with XSD and DTD.
1 PageBeginnerFeb 2, 2026
Document Structure
Declaration, elements, and attributes.
xml
<?xml version="1.0" encoding="UTF-8"?><library> <book id="b1" available="true"> <title>The Pragmatic Programmer</title> <author>David Thomas</author> <price currency="USD">39.99</price> </book> <!-- This is a comment --></library>
Namespaces
Avoiding element name collisions across vocabularies.
xml
<root xmlns:h="http://www.w3.org/TR/html4/" xmlns:f="https://example.com/furniture"> <h:table> <h:tr><h:td>Apples</h:td></h:tr> </h:table> <f:table> <f:width>80</f:width> </f:table></root>
XPath Basics
Selecting nodes within an XML document.
xml
/library/book <!-- all book children of library -->//title <!-- all title elements, any depth -->/library/book[@id='b1'] <!-- book with id attribute b1 -->/library/book[1] <!-- first book element -->//book/author/text() <!-- text content of author -->//price[@currency='USD'] <!-- price elements with attribute -->
Key Concepts
Core terminology and validation approaches.
- Well-formed- Every opening tag has a matching closing tag and tags are properly nested
- Valid- Well-formed AND conforms to a schema (DTD or XSD)
- Attribute vs. element- Attributes hold metadata on a tag; elements hold structured/nested content
- CDATA section- `<![CDATA[ raw text ]]>` prevents special characters from being parsed as markup
- Entity references- `<` `>` `&` `'` `"` escape reserved characters
- XSD- XML Schema Definition; defines allowed structure, types, and constraints for validation
Pro Tip
Every XML document can have only one root element — if you need multiple top-level items, wrap them in a single container element.
Was this cheat sheet helpful?
Explore Topics
#XMLBasics#XMLBasicsCheatSheet#ToolsOthers#Beginner#DocumentStructure#Namespaces#XPathBasics#KeyConcepts#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance