DTD Question surrounding duplicate child elements

Discussion in 'XML' started by Doug Estep, Feb 1, 2004.

  1. Doug Estep

    Doug Estep Guest

    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
    Doug Estep, Feb 1, 2004
    #1
    1. Advertising

  2. In article <>,
    Doug Estep <> 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!
    Richard Tobin, Feb 1, 2004
    #2
    1. Advertising

  3. Doug Estep

    Doug Estep Guest

    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!


    (Richard Tobin) wrote in message news:<bvjurk$l4c$>...
    > In article <>,
    > Doug Estep <> 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
    Doug Estep, Feb 2, 2004
    #3
  4. In article <>,
    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.

    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
    Patrick TJ McPhee, Feb 2, 2004
    #4
  5. 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
    Oliver Bonten, Feb 2, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Joseph Tilian
    Replies:
    0
    Views:
    339
    Joseph Tilian
    Dec 21, 2004
  2. Ronald Fischer
    Replies:
    4
    Views:
    1,743
    Ronald Fischer
    Mar 17, 2005
  3. Gerald Aichholzer
    Replies:
    2
    Views:
    2,482
    Gerald Aichholzer
    Jun 27, 2006
  4. Jeff Rodriguez
    Replies:
    23
    Views:
    1,089
    David Schwartz
    Dec 9, 2003
  5. Ken Fine
    Replies:
    4
    Views:
    195
    Ken Fine
    Aug 14, 2003
Loading...

Share This Page