• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Multiple Root Elements in DTD

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good example Mapraputa.
 
Damodharan Ramabhadran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mapraputa.
 
Heroic work plunger man. Please allow me to introduce you to this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic