Question

I tried internal and external DTD's both with a name different than the root element name , it still Works!.

Its about the value of "Name" in the tag below -

<DOCTYPE Name SYSTEM "Couple.dtd">

What's the use of this "Name" then?

1)Internal DTD

<!DOCTYPE  SampleDocType[
<!ELEMENT Neighbours (Couple, Couple) >
<!ELEMENT Couple (Name, Name) >
<!ELEMENT Name ( Vorname, Nachname, Geschlecht) >
<!ELEMENT Vorname (#PCDATA) >
<!ELEMENT Nachname (#PCDATA) >
<!ELEMENT Geschlecht (#PCDATA) >
]>

<Couple>

    <Name>

        <Vorname>Marie</Vorname>

        <Nachname>M&#252;ller</Nachname>

        <Geschlecht>&#61;</Geschlecht>

    </Name>

    <Name>


        <Vorname>Klaus</Vorname>

        <Nachname>M&#xfc;ller</Nachname>

        <Geschlecht>♂</Geschlecht>

    </Name>

</Couple>

2)External DTD

<!DOCTYPE SampleDocType SYSTEM "Couple.dtd" >

<Couple>

<Name>

 <Vorname>Marie</Vorname>

 <Nachname>M&#252;ller</Nachname>

 <Geschlecht>&#61;</Geschlecht>

</Name>

<Name>


 <Vorname>Klaus</Vorname>

 <Nachname>M&#xfc;ller</Nachname>

 <Geschlecht>♂</Geschlecht>

</Name>

</Couple>

external DTD file

<!ELEMENT Neighbours ( Couple, Couple) >
<!ELEMENT Couple (Name, Name) >
<!ELEMENT Name ( Vorname, Nachname, Geschlecht) >
<!ELEMENT Vorname (#PCDATA) >
<!ELEMENT Nachname (#PCDATA) >
<!ELEMENT Geschlecht (#PCDATA) >

Note - I am using XMLtools plugin in Notepad++ for validation.

Was it helpful?

Solution

You ask What's the use of "Name" in ... <!DOCTYPE Name SYSTEM "Couple.dtd">?

Like all intentional redundancies, the Name in the XML document type declaration allows for consistency checking. In SGML (from which XML inherited the syntax of the declaration) the checking may be more important, since the document type declaration and the start-tag of the document's outermost element may be in different files or entities. Since XML requires that the document type declaration (if present) be in the same data stream as the tags of the document's outermost element, there is less obvious need for the redundancy in XML, and it would not be too far off to say that the name is retained for compatibility with SGML.

OTHER TIPS

Per the spec (1.0 and 1.1):

The Name in the document type declaration MUST match the element type of the root element.

If your tool is not reporting this as an error, I believe it is the fault of the tool.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top