Este ejemplo muestra una DTD XML en un documento XML y el formato de estructura en árbol de dicho documento:
<!DOCTYPE test PUBLIC "//this/is/a/URI/test" "test.dtd" [
<!NOTATION TeX PUBLIC "//this/is/a/URI/TexID" "//TexID">
<!ENTITY ent1 "esto es una entidad">
<!ENTITY % ent2 "#PCDATA | subel2">
<!ENTITY % extent1 PUBLIC "//this/is/a/URI/extent1" "more.txt">
<!ENTITY extent2 PUBLIC "//this/is/a/URI/extent2" "more.txt">
<!ENTITY unpsd PUBLIC "//this/is/a/URI/me.gif" "me.gif" NDATA TeX>
<?test Do this?>
<!--esto es un comentario-->
<!ELEMENT subel2 (#PCDATA)>
<!ELEMENT subel1 (subel2 | el4)+>
<!ELEMENT el1 (#PCDATA)>
<!ELEMENT el2 (#PCDATA | subel2)*>
<!ELEMENT el3 (#PCDATA | subel2)*>
<!ELEMENT el4 (#PCDATA)>
<!ELEMENT el5 (#PCDATA | subel1)*>
<!ELEMENT el6 (#PCDATA)>
<!ATTLIST subel1
size (big | small) "big"
shape (round | square) #REQUIRED>
<!ATTLIST el5
el5satt CDATA #IMPLIED>
]>
Cuando un analizador XML genérico analiza un mensaje, la parte relevante del árbol de mensaje tiene este aspecto (suponiendo que no haya retornos de carro ni espacios en blanco entre códigos):
La estructura IntSubset contiene las estructuras siguientes en el siguiente nivel de anidamiento: la estructura en árbol para cada una de éstas se muestra en las estructuras en árbol siguientes.