Getting Started
4 snippetsXML basics and structure
Basic Structure
<?xml version="1.0" encoding="UTF-8"?>
<root>
<child>Content</child>
</root>XML Declaration
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>Comments
<!-- This is a comment -->
<!--
Multi-line
comment
-->Root Element
<?xml version="1.0"?>
<root>
<!-- Must have exactly ONE root element -->
</root>Elements
5 snippetsTags and nesting
Opening and Closing Tags
<person>
<name>John</name>
<age>30</age>
</person>Self-Closing Tags
<image src="photo.jpg" />
<br />
<input type="text" />Nested Elements
<company>
<department>
<employee>
<name>Alice</name>
</employee>
</department>
</company>Empty Elements
<description></description>
<!-- or -->
<description />Case Sensitivity
<Person> <!-- Different from -->
<person> <!-- these are NOT the same -->Attributes
4 snippetsElement attributes
Basic Attributes
<person id="123" type="employee">
<name>John</name>
</person>Quoted Values
<img src="photo.jpg" alt="Photo" />
<input type="text" value="default" />Single vs Double Quotes
<tag attr="value">
<tag attr='value'>
<!-- Both are valid -->Multiple Attributes
<person id="123" name="John" age="30" active="true" />Tired of looking up syntax?
DocuWriter.ai generates documentation and explains code using AI.
Text Content
4 snippetsText nodes and CDATA
Text Content
<message>Hello, World!</message>
<description>This is some text content.</description>Mixed Content
<paragraph>
This is <bold>bold</bold> and <italic>italic</italic> text.
</paragraph>CDATA Section
<script>
<![CDATA[
function test() {
if (x < 5 && y > 10) {
return true;
}
}
]]>
</script>Whitespace
<text> Leading and trailing spaces preserved </text>Special Characters
4 snippetsEscaping and entities
Predefined Entities
< <!-- < -->
> <!-- > -->
& <!-- & -->
' <!-- ' -->
" <!-- " -->Character References
A <!-- A (decimal) -->
A <!-- A (hexadecimal) -->
© <!-- © -->Usage in Text
<message>5 < 10 && 10 > 5</message>
<quote>He said "Hello"</quote>Usage in Attributes
<link url="http://example.com?a=1&b=2" />
<tag value="<value>" />Namespaces
3 snippetsXML namespaces
Default Namespace
<root xmlns="http://www.example.com/schema">
<child>Content</child>
</root>Namespace Prefix
<root xmlns:custom="http://www.example.com/custom">
<custom:element>Content</custom:element>
</root>Multiple Namespaces
<root xmlns:a="http://a.com"
xmlns:b="http://b.com">
<a:item>A content</a:item>
<b:item>B content</b:item>
</root>Processing Instructions
2 snippetsPI and stylesheets
Processing Instruction
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<?custom-instruction data="value"?>Link to XSL
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
<root>...</root>Common Use Cases
3 snippetsReal-world XML examples
Configuration File
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="timeout" value="30" />
<add key="retries" value="3" />
</appSettings>
</configuration>Data Document
<?xml version="1.0"?>
<users>
<user id="1">
<name>Alice</name>
<email>alice@example.com</email>
</user>
<user id="2">
<name>Bob</name>
<email>bob@example.com</email>
</user>
</users>RSS Feed
<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title>My Blog</title>
<link>http://example.com</link>
<item>
<title>Post Title</title>
<description>Post content</description>
</item>
</channel>
</rss>