467,920 Members | 1,248 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,920 developers. It's quick & easy.

DTD Question surrounding duplicate child elements

Below is a sample of my XML…

<MetaData>
<Table name="mytable">
<PrimaryKey name="pk"><Column name="mycolumn"/></PrimaryKey>
</Table>
</MetaData>

<Sequencer>
<Table name="mytable">
<Column name="mycolumn">
<Type>Object</Type>
</Column>
</Table>
</Sequencer>

Notice that I have two elements called, MetaData and Sequencer that
both have child elements called Table. How do I define the Table
child element in a DTD? Let me continue to explain what I mean. To
define the DTD for the two parent elements, I would do the following…

<!ELEMENT MetaData (Table+)>
<!ELEMENT Sequencer(Table+)>

Now I want to define the Table elements for both the MetaData and the
Sequencer elements. How do I do that when both child elements are
named Table. This is valid XML. But I can't see how I can create a
DTD for this XML when I can't define duplicate element names in a DTD.

I'm new to XML, so this may be a dumb question. I hope that it is,
because if this cannot be done, then defining a DTD is a worthless
exercise in any serious business application, in my opinion.

Your help is greatly appreciated. Please refrain from telling me how
I can work around this by structuring my XML in another way. I know
that I can do that. I am more interested in if it is possible to have
two parent elements with child elements that have the same name and be
able to define that in a DTD.

Thanks,
Doug
Jul 20 '05 #1
  • viewed: 6121
Share:
4 Replies
In article <dc**************************@posting.google.com >,
Doug Estep <do***********@webtechinfo.com> wrote:
Notice that I have two elements called, MetaData and Sequencer that
both have child elements called Table. How do I define the Table
child element in a DTD?
You can't have two elements with the same name and different content
models in the same DTD. In DTDs, an element type is determined by its
name.

XML Schemas allow elements with the same name to have different types
in different context, but DTDs don't.
I'm new to XML, so this may be a dumb question. I hope that it is,
because if this cannot be done, then defining a DTD is a worthless
exercise in any serious business application, in my opinion.


I hear that DTDs have been used in thousands of serious business
applications, but I suppose it's possible that you're right and
they're all wrong.

-- Richard
--
Spam filter: to mail me from a .com/.net site, put my surname in the headers.

FreeBSD rules!
Jul 20 '05 #2
Thanks for your help Richard. If the purpose of a DTD is to define
the rules for an XML file and the XML file can define child elements
for a parent which may have the same name as another parents child
elements.... and the DTD cannot handle that situation.... then I do
think there is a flaw in the DTD design.

My solution is to name my child nodes uniquely with regards to the
entire XML file. Certainly that can be done.

My comment about "Serious" business applications was directed at
situations where you have very large XML files -- which "serious"
business applications are sure to have. With a very large XML file, I
think it would be challenging to put together a DTD if the XML file
can never have a child element with the same name as another child
element within another parent.

But hey...nothing personal man!
ri*****@cogsci.ed.ac.uk (Richard Tobin) wrote in message news:<bv**********@pc-news.cogsci.ed.ac.uk>...
In article <dc**************************@posting.google.com >,
Doug Estep <do***********@webtechinfo.com> wrote:
Notice that I have two elements called, MetaData and Sequencer that
both have child elements called Table. How do I define the Table
child element in a DTD?


You can't have two elements with the same name and different content
models in the same DTD. In DTDs, an element type is determined by its
name.

XML Schemas allow elements with the same name to have different types
in different context, but DTDs don't.
I'm new to XML, so this may be a dumb question. I hope that it is,
because if this cannot be done, then defining a DTD is a worthless
exercise in any serious business application, in my opinion.


I hear that DTDs have been used in thousands of serious business
applications, but I suppose it's possible that you're right and
they're all wrong.

-- Richard

Jul 20 '05 #3
In article <dc**************************@posting.google.com >,
Doug Estep <do***********@webtechinfo.com> wrote:
% Thanks for your help Richard. If the purpose of a DTD is to define
% the rules for an XML file and the XML file can define child elements
% for a parent which may have the same name as another parents child
% elements.... and the DTD cannot handle that situation.... then I do
% think there is a flaw in the DTD design.

You keep leaving out `but different content models' when you say `have
the same name'. If you want to go around slagging DTDs, at least make
your description of the problem complete. DTDs were not designed to
accomodate this sort of document, but that doesn't make them worthless for
any serious application. Anyway, you can write a DTD which will validate
your document, but it will also validate documents which don't conform
to your design. I don't think it's possible to create a well-formed XML
document for which you can't create a matching DTD.

You should probably look at RELAX NG or W3C Schemas and see if they are
better for your purposes.

--

Patrick TJ McPhee
East York Canada
pt**@interlog.com
Jul 20 '05 #4
On Mon, 02 Feb 2004 08:11:36 +0000, Doug Estep wrote:
Thanks for your help Richard. If the purpose of a DTD is to define
the rules for an XML file and the XML file can define child elements
for a parent which may have the same name as another parents child
elements.... and the DTD cannot handle that situation.... then I do
think there is a flaw in the DTD design.


My opinion is that it is a flaw in the XML Schema Design that it *does*
allow you to use context-dependent content models. (Or, in other words,
have two different elements with the same name.) This creates a lot of
headache and has no productive use, except to underline programmer's
preference for elegant solutions over comprehensible ones.

In DTDs, things are called by their names, and if two elements have the
same name, they are the same. You can have a TABLE in MetaData and a TABLE
in Sequencer, but they have to be interchangeable. You cannot define
different rules for TABLE in MetaData and for TABLE in Sequencer. If you
want to define different rules for TABLE in MetaData and for TABLE in
Sequencer, they are actually semantically different objects and should get
different names, such as MetaDataTable and SequencerTable.

Oliver
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Robert | last post: by
1 post views Thread by marx | last post: by
1 post views Thread by Miguel Isidoro | last post: by
4 posts views Thread by Keith Patrick | last post: by
14 posts views Thread by marfi95 | last post: by
3 posts views Thread by spl | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.