473,405 Members | 2,310 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
4 6736
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robert | last post by:
Im a beginner in PHP and Im having a problem with this code. Im trying to remove duplicate elements from an array created via $_GET. I want users to be able to click on a link which sends an email...
1
by: marx | last post by:
I have a bit of a problem and any help would be much appreciated. Problem: I have two dropdown list boxes with same data(all data driven). These are used for two separate entries. For every...
1
by: adamredwards | last post by:
I have a page with some form elements that are dynamically generated. They are inserted into the dom by first cloning a node, changing the values like name, and then inserted with insertBefore(). ...
1
by: Miguel Isidoro | last post by:
I generated a .cs class from a .xsd schema using the xsd.exe tool from Visual Studio 2005 and noticed that is generating duplicate class declarations. This happens because of my schema structure. I...
4
by: patrizio.trinchini | last post by:
Hi all, I'm new to XSLT and maybe my problem have a very trivial answer, but I need an expert that point me in the right direction. What I would obtain is to remove all the elements that have a...
4
by: Keith Patrick | last post by:
I'm trying to parse some XML via IXPathNavigable, handling elements, text, and attributes with the same code but without having a switch (node.NodeType). However, if I look at a parent element in...
14
by: marfi95 | last post by:
I'm trying to iterate through a list of child nodes. It seems like to get the text value of the node, you have to do a node->getFirstChild()->getNodeValue. This being said, there is a...
3
by: spl | last post by:
What is the fastest way to find a duplicate value in an array of 10 elements. I have to find just any one first occurrence of the duplication. Lets say I have ary={10, 20, 40, 90, 30, 60, 35, 40,...
7
by: swami | last post by:
What is the query for selecting non duplicate elements for eg: no name age 1 siva 28 2 blair 32 3 mano 28 i want to select blair which hasn't got any duplicate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.