• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Multiple Root Elements in DTD

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is regarding the generation of DTD's. There are certain cases when the root element of a DTD has to change since the basic XML's root element changes. The requirement is that the same DTD is needed to do the job for different XML's. Can we make the DTD accept either 'firstType' or 'secondType' as the root element(in the example shown below)? If yes, how would the DTD look like?

The XML
<?xml version="1.0" standalone="no"?>
<!DOCTYPE "firstType" SYSTEM "basic.dtd">
<firstType>
<elementA>
data
</elementA>
</firstType>
<!DOCTYPE "secondType" SYSTEM "basic.dtd">
<secondType>
<elementB>
data
</elementB>
</secondType>
Regards,
Damodharan
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use parameter entity and declare your root element as %root
basic.dtd:
<!ELEMENT %root; (elementA | elementB)+>
<!ELEMENT elementA (#PCDATA)>
<!ELEMENT elementB (#PCDATA)>

then in your XML files you can have both external subset (basic.dtd) and internal subset, in which you assign a value to %root entity:
<?xml version="1.0" standalone="no"?>
<!DOCTYPE firstType SYSTEM "basic.dtd" [
<!ENTITY % root "firstType">
]>
<firstType>
<elementA>data</elementA>
</firstType>

and
<?xml version="1.0" standalone="no"?>
<!DOCTYPE secondType SYSTEM "basic.dtd" [
<!ENTITY % root "secondType">
]>
<secondType>
<elementA>data</elementA>
</secondType>

Your real data may be different from an example you gave, so you may need to change DTD accordingly, but the basic idea should work.
 
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good example Mapraputa.
 
Damodharan Ramabhadran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mapraputa.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!