Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DTD root element

Tags:

xml

root

dtd

Is it possible to define which element will be the root element in a DTD internally. In other words, Is it possible to define the root element when DTD is in a separate file?

like image 375
temelm Avatar asked Oct 25 '11 16:10

temelm


1 Answers

The root element is determined by the DOCTYPE declaration. The root element can be any element in the DTD.

For example in the DTD below (test.dtd), book would normally be the root element:

<!ELEMENT book (chapter+)>
<!ELEMENT chapter (section+)>
<!ELEMENT section EMPTY>

However, if we use section in the doctype, section is the root element:

<!DOCTYPE section SYSTEM "test.dtd">
<section/>

I've used DOCTYPE declarations in the external DTD to directly specify the root element, but I don't think that is allowed by the spec. What I did was keep the DOCTYPE in the external DTD and remove the DOCTYPE from the XML file. I was able to associate the DTD with the XML file on the command line of the program I was using.

like image 55
Daniel Haley Avatar answered Nov 15 '22 09:11

Daniel Haley