<book> <title> eXtensible <bold>Markup</bold> Language </title> </book>An element is defined by an opening tag (e.g., "<bold>"), content (e.g., "Markup"), and a closing tag (e.g., "</bold>"). The name of the opening tag (e.g., "<bold>") must match the corresponding closing tag name (e.g., "</bold>").
book
" element is the parent of the "title
" element.title
" element is the child or sub-element of the "book
" element.book
" element contains a single child element:title
" element.title
" element contains three child nodes:bold
" element.bold
" element contains a single child node:<emptyTag />
<anotherEmptyTag></anotherEmptyTag>Note that that self-closing tags (like
<emptyTag />
) are preferred for empty elements as they're more concise and clearly indicate the element has no content.<book><title>XML</title></book>Here's an example of Incorrect nesting (overlapping tags):
<book><title>XML</book></title>
book
").<Book>
and <book>
are different elements.<character >A</character>
<character>A</character >
<character >A</character >
<character >A</character>
<character.1-code />
< character>A</character>
<character>A< /character>
<character>A</ character>
<1character />
<character code />
<character=code />
<file type="text" encoding="UTF-8" extension="" />Tag naming rules also apply to attribute names.
type = "text"
is valid).<file type>
<file type=text>
<file type="text" />
<!-- comment -->Comments can span multiple lines:
<!-- This is a multi-line comment -->Examples of invalid comments:
<file <!-- comment --> />
<!-- comment -- more comment -->
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>Notes:
UTF-8
- Most common, supports all Unicode charactersUTF-16
- Unicode encoding using 16-bit unitsISO-8859-1
- Latin-1 character setUS-ASCII
- Basic ASCII characters<?xml-stylesheet type="text/xsl" href="style.xsl"?> <?php echo "Hello World"; ?> <?python import sys; print("XML processing") ?>Note: The target name (first word after <?) cannot be "xml" (in any case combination), as this is reserved.
&
represents the character &
<
represents the character <
>
represents the character >
'
represents the character "
"
represents the character "
&
and <
must always be escaped in element content>
should be escaped for consistency, though it's only required in the sequence ]]>
'
and "
need escaping only when they appear in attribute values using the same quote typeCDATA
" keyword to escape characters.<![CDATA[
" and "]]>
" is ignored by the parser and treated as raw text.<title><![CDATA[Extensible <Markup> Language]]></title>CDATA sections are particularly useful for:
]]>
.&#nnn;
where "nnn
" is the decimal code of the character.©
represents the character ©
&#xhhhh;
where "hhhh
" is the hexadecimal code of the character.©
represents the character ©
<?xml version="1.0"?> <!DOCTYPE book [ <!ELEMENT book (title, isbn)> <!ELEMENT title (#PCDATA)> <!ELEMENT isbn (#PCDATA)> ]> <book> <title>XML</title> <author>MTI TEK</author> <!-- ERROR: 'author' not declared in DTD --> <isbn>123</isbn> </book>Note: XML parsers can validate documents against DTDs to ensure they are both well-formed and valid. Most XML processing applications require documents to be at least well-formed, while some also require validity.