Should <?xml version="1.0"?> be in a DTD?

A

admyc

Hello,

I am learning XML and have a question about DTDs.

I understand the line:
<?xml version="1.0"?>
in an XML document to be there to tell the program dealing with the
document that it is a document written in XML and the version of XML
it is written in is version 1.0.

When it comes to DTDs I have seen some examples where this line ('<?
xml version="1.0"?>'), is included in the DTD too and I can't
understand why it is there.

In an XML document this line is there to declare it as an XML document
but a DTD is not an XML document so I can not see why it is there.

I think that this line should not be in a DTD as I can't figure out
what possible use it is. Can anyone either confirm that this line is
erroneously included in some DTD examples or tell me what possible use
it can server in one?

Thanks

AM
 
M

Martin Honnen

admyc said:
I understand the line:
<?xml version="1.0"?>
in an XML document to be there to tell the program dealing with the
document that it is a document written in XML and the version of XML
it is written in is version 1.0.

When it comes to DTDs I have seen some examples where this line ('<?
xml version="1.0"?>'), is included in the DTD too and I can't
understand why it is there.

In an XML document this line is there to declare it as an XML document
but a DTD is not an XML document so I can not see why it is there.

I think that this line should not be in a DTD as I can't figure out
what possible use it is. Can anyone either confirm that this line is
erroneously included in some DTD examples or tell me what possible use
it can server in one?


See <URL:http://www.w3.org/TR/REC-xml/#sec-prolog-dtd> about the "text
declaration" that the external subset can begin with. So
<?xml version="1.0"?>
or
<?xml version="1.0" encoding="UTF-16"?>
is perfectly right at the beginning of an external subset (DTD).
 
R

Richard Tobin

Martin Honnen said:
See <URL:http://www.w3.org/TR/REC-xml/#sec-prolog-dtd> about the "text
declaration" that the external subset can begin with. So
<?xml version="1.0"?>
or
<?xml version="1.0" encoding="UTF-16"?>
is perfectly right at the beginning of an external subset (DTD).

Somewhat strangely, the EncodingDecl is required in a TextDecl (though
not in an XMLDecl). So <?xml version="1.0"?> is not allowed in an
external DTD.

-- Richard
 
M

Martin Honnen

Richard said:
Somewhat strangely, the EncodingDecl is required in a TextDecl (though
not in an XMLDecl). So <?xml version="1.0"?> is not allowed in an
external DTD.

Right. VersionInfo is optional however in TextDecl.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top