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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With