Discussion:
How to define a DTD with entities that share the same sub-entity name
(too old to reply)
h***@gmail.com
2005-10-07 06:35:24 UTC
Permalink
Hi Folks
I would appreciate it if you could help me out with a problem I am
facing while defining a DTD as illustrated below:

<!ELEMENT SQLParser (updateOrder,primaryKeys)

<!ELEMENT updateOrder (cols+)>
<!ELEMENT cols (col+)>
<!ELEMENT col (#PCDATA)>

<!ELEMENT primaryKeys (cols+)>
<!ELEMENT cols (col+)>
<!ELEMENT col (#PCDATA)>

As both updateOrder and primaryKeys have the same sub-elements - I get
an error while defining the DTD which complains of duplicate entities
for 'cols' and 'col' entities. What do I need to do in order to get
around this problem (without having to rename the 'cols' element? Is
there a way to scope or namespace the 'cols' and 'col' entity with the
parent entity?

Any help with this matter is appreciated.

Regards,
-Haridev
Michael Piotrowski
2005-10-07 08:31:56 UTC
Permalink
Post by h***@gmail.com
I would appreciate it if you could help me out with a problem I am
<!ELEMENT SQLParser (updateOrder,primaryKeys)
<!ELEMENT updateOrder (cols+)>
<!ELEMENT cols (col+)>
<!ELEMENT col (#PCDATA)>
<!ELEMENT primaryKeys (cols+)>
<!ELEMENT cols (col+)>
<!ELEMENT col (#PCDATA)>
As both updateOrder and primaryKeys have the same sub-elements - I get
an error while defining the DTD which complains of duplicate entities
for 'cols' and 'col' entities. What do I need to do in order to get
around this problem (without having to rename the 'cols' element? Is
there a way to scope or namespace the 'cols' and 'col' entity with the
parent entity?
The solution is simple: Declare cols and col only once, i.e.:

<!ELEMENT SQLParser (updateOrder,primaryKeys)

<!ELEMENT updateOrder (cols+)>
<!ELEMENT primaryKeys (cols+)>

<!ELEMENT cols (col+)>
<!ELEMENT col (#PCDATA)>

There is no hierarchical structure in a DTD, but all element
declarations are global--it doesn't make a difference if you declare
element B above or below element A.

HTH
--
Michael Piotrowski, M.A. <***@dynalabs.de>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt>
h***@gmail.com
2005-10-07 11:03:16 UTC
Permalink
Thanks for your reply Michael.

However this implies that one cannot overload by entity name if the
data types are different (pardon my OO language)
I checked the DTD spec on w3.org but couldnt find anything useful in
this regard.

Regards,
-Haridev
David Carlisle
2005-10-07 15:36:12 UTC
Permalink
However this implies that one cannot overload by entity name if the
data types are different (pardon my OO language)

Yes (or rather you need to define the element with a wide enough content
type that it can be used in both contexts)

I checked the DTD spec on w3.org but couldnt find anything useful in
this regard.

Of course the W3C only give the definition of XML DTD not the rather
more powerful SGML DTD, but in either case element declarations are
essentially global.

If you are using XML (rather than SGML) and need to define local element
types then alternative schema languages such as Relax NG (or XSD, the
W3C XML schema language) will come to your aid. (Note you do mean, I
think element name rather than entity name.)

David

Loading...