Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

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

 
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
 
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
 
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
 
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
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic