File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Product and Other Certifications and the fly likes DTD...declaring an element which has child elements and PCDATA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Product and Other Certifications
Bookmark "DTD...declaring an element which has child elements and PCDATA" Watch "DTD...declaring an element which has child elements and PCDATA" New topic
Author

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

Shoba Ramachandran
Ranch Hand

Joined: Mar 29, 2001
Posts: 68
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

Joined: Jun 05, 2002
Posts: 5
I think this will work for Mixed content
<!ELEMENT id (#PCDATA|name| address)*>
Shoba Ramachandran
Ranch Hand

Joined: Mar 29, 2001
Posts: 68
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

Joined: Aug 28, 2001
Posts: 29
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

Joined: Apr 04, 2001
Posts: 93
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DTD...declaring an element which has child elements and PCDATA