• Post Reply Bookmark Topic Watch Topic
  • New Topic

DTD...declaring an element which has child elements and PCDATA

 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
This is my xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE person SYSTEM "test.dtd">
<?xml-stylesheet type="text/xsl" href="test1.xsl"?>
<person>
<id number="33432">
<name>shoba</name>
<address>
<street>nowhere</street>
<city>nocity</city>
<zip>77056</zip>
</address>
<address>
<street>nostreet</street>
<city>nocity</city>
</address>
</id>
<id number="766665" dept="ee" perid="890">
<name>shoba1</name>
<address>
<street>nostreet1</street>
<city>nocity1</city>
<zip>889909</zip>
</address>
<address>
<street>nostreet1</street>
<city>nocity1</city>
</address>
</id>
</person>
and this is my dtd
<?xml version="1.0" encoding="UTF-8"?>
<!ENTITY manager "Shoba">
<!ELEMENT person (id+)>
<!ELEMENT id (name, address+)>
<!ATTLIST id
number CDATA #IMPLIED
dept (2it | ec | ee) #IMPLIED
hod ENTITY #IMPLIED
perid CDATA #FIXED "890"
>
<!ELEMENT name (#PCDATA)>
<!ELEMENT address (street, city, zip?)>
<!ELEMENT city (#PCDATA)>
<!ELEMENT street (#PCDATA)>
<!ELEMENT zip (#PCDATA)>
If I want to make the <id> element node to have both child element nodes and text node, how do i declare that in dtd.
If I change in DTD as follows...throws error.
<!ELEMENT id (name, address+)> to
<!ELEMENT id (name, address+)(#PCDATA)>
How do I do this kind of stuff?
Thanks
Shoba
 
Gobiraj Vadivelrajan
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this will work for Mixed content
<!ELEMENT id (#PCDATA|name| address)*>
 
Shoba Ramachandran
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But Gopiraj, then it would allow zero or more number of names and addresses. I don't want that..I need that <id> has one <name> and one or more <address> and a text. How to do this?
Thanks
Shoba
 
PC RE
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shoba,
I don't think u can do that with DTD. That is one of the disadvantage of DTD over Schemas.
Thanks,-PC RE
 
Danl Thompson
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This link should clear things up:
http://www.w3.org/TR/2000/REC-xml-20001006#NT-Mixed
In cases of Mixed content, child elements may be constrained but not their order or number of occurances....
That's why we like schemas!
Dan'l
 
The moth suit and wings road is much more exciting than taxes. Or this tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!