• 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic