Reputation: 149
I'm a beginner on XML and DTD and i can't figure one thing out. How do i declare elements with the same name(on XML) on a DTD? Here's my XML file to see what i mean.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE family SYSTEM "family.dtd">
<family>
<Name>
<FirstName>George</FirstName>
<LastName>Costanza</LastName>
</Name>
<Name>
<FirstName>Jerry</FirstName>
<FirstName>Allen</FirstName>
<LastName>Seinfeld</LastName>
<Phone>0522-112233</Phone>
</Name>
<Name>
<FirstName>Elaine</FirstName>
<LastName>Benes</LastName>
<Phone>0522-998877</Phone>
<Phone>070-100101</Phone>
<vip></vip>
</Name>
</family>
As you can see the element "Name" is used several times. I tried this on my DTD but it of course says the element Name has already been declared.
<!ELEMENT family (Name+)>
<!ELEMENT Name (FirstName, LastName)>
<!ELEMENT FirstName(#PCDATA)>
<!ELEMENT LastName(#PCDATA)>
<!ELEMENT Name (FirstName, FirstName, LastName, Phone)>
So how would i get around this problem? I hope i made myself clear.
Upvotes: 2
Views: 1776
Reputation: 4568
Your DTD has different definitions for Name
, which is not helpful. You possibly wish to make some of them able to occur zero of more times, e.g.
<!ELEMENT family (Name+)>
<!ELEMENT Name (FirstName+, LastName, Phone*)>
<!ELEMENT FirstName (#PCDATA)>
<!ELEMENT LastName (#PCDATA)>
where +
is declaring that the named element will occur one or more times in the block, and *
is declaring that the named element will occur zero or more times. If you don't have any quantifier, then the named element will occur only once.
Also note that you are missing a space between some of the element names and the content-types, namely FirstName
and (#PCDATA)
, for example.
Finally, where is the opening tag of vip
?
Upvotes: 2