*
The moose likes XML and Related Technologies and the fly likes how many root element can be defined in one dtd files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "how many root element can be defined in one dtd files" Watch "how many root element can be defined in one dtd files" New topic
Author

how many root element can be defined in one dtd files

will wang
Greenhorn

Joined: Dec 10, 2002
Posts: 6
is there only one root element can defined in one dtd file or no limitation? i konw if the dtd is declared in the xml file,there should be only one ,just the root element of that xml file,but how about the case if the dtd is declared in one file?
[ January 30, 2003: Message edited by: will wang ]
usha raju
Greenhorn

Joined: Jan 30, 2003
Posts: 3
If you define DTD in a separate file, it will be stored as .DTD file. Then also XML file which uses this DTD follows the structure as defined in DTD. ie, an XML file can have one & only one root element, which defines the beginning & ending of XML data file.For example,you have defined a simple DTD as (say address.dtd):
<!ELEMENT ADDRESSBOOK (ENTRY+)>
<!ELEMENT ENTRY (NAME, ADDRS, PHONE)>
<!ELEMENT NAME (#PCDATA)>
<!ELEMENT ADDRS (#PCDATA)>
<!ELEMENT PHONE (#PCDATA)>
Then in XML data file, you give entries as :
<!DOCTYPE addressbook SYSTEM "addresses.dtd">
<ADDRESSBOOK>
<ENTRY>
<NAME>prathap</NAME>
<ADDRS>THE NOOK</ADDRS>
<PHONE>JOHN@HOME.COM</PHONE>
</ENTRY>
.......
</ADDRESSBOOK>
First line in XML file specifies which DTD the parser should use to validate XML.
Steven Broadbent
Ranch Hand

Joined: Dec 10, 2002
Posts: 400
Is that true that using xml schema you can
define more than one document element?


"....bigmouth strikes again, and I've got no right to take my place with the human race...."<p>SCJP 1.4
will wang
Greenhorn

Joined: Dec 10, 2002
Posts: 6
if two xml files use the same DTD file,such as address.dtd,is is true that these two xml files can have different root element?
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
Originally posted by will wang:
is there only one root element can defined in one dtd file or no limitation? i konw if the dtd is declared in the xml file,there should be only one ,just the root element of that xml file,but how about the case if the dtd is declared in one file?
[ January 30, 2003: Message edited by: will wang ]

DTD file does not define root ELEMENT at all. You can define as many ELEMENT as you want. Every ELEMENT can be used as root ELEMENT of your XML file. However, your XML would be constraint by that ELEMENT you have chosen.
See this is a valid XML. Try it! Seeing is believing

XMLSchema is working in the same fashion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how many root element can be defined in one dtd files