XML
Beginner
1 min read
Element Naming Rules and Best Practices
Example
<?xml version="1.0" encoding="UTF-8"?>
<namingExamples>
<!-- Valid element names -->
<firstName>Alice</firstName>
<first-name>Alice</first-name>
<first_name>Alice</first_name>
<_internalId>42</_internalId>
<item1>value</item1>
<!-- Names with Unicode letters are valid -->
<données>some data</données>
<!--
INVALID names (shown as comments to keep document well-formed):
<1stItem> — starts with digit
<my item> — contains space
<my@item> — contains @
<xmlFoo> — starts with 'xml' (reserved)
<-bar> — starts with hyphen
-->
<!-- Namespace-prefixed names (valid when namespace declared) -->
<book xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:title>Learning XML</dc:title>
<dc:creator>Jane Doe</dc:creator>
<dc:date>2025-01-15</dc:date>
</book>
</namingExamples>