Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DTD for this XML

 
Ramesh Balasubramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am looking for the DTD for this XML. Can you please help me out.
Thx.
<pre>

<letter>
Dear Mr.<name>John Smith</name>.
Your order <orderid>1032</orderid>
will be shipped on <shipdate>2001-07-13</shipdate>.
</letter>
</pre>
 
Sridhar Kilambi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<!DOCTYPE pre (letter, name, orderid, shipdate)
<!ATTLIST letter (#PCDATA)
name (#PCDATA)
orderid (#PCDATA)
shipdate (#PCDATA) >
I am NOT sure of this. plz verify with experts present here. but this should give u an general idea.
regards
sridhar
---------------------------------------
aspirant for xml 141 cert.
 
Syed AliRaza Zaidi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the correct DTD one which was posted previously is not correct
<!ELEMENT pre(letter)>
<!ELEMENT letter(#PCDATA|name|orderid|shipdate)>
<!ELEMENT name(#PCDATA)>
<!ELEMENT orderid(#PCDATA)>
<!ELEMENT shipdate(#PCDATA)>
This is typically mixing of element contents
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Syed,
there is a slight problem with your DTD. As you can see mixed content can be found several times in the XML document provided by Ramesh.
Here is the correct DTD:

Note that:
- There's a star (*) after (#PCDATA | name | orderid | shipdate) since #PCDATA can be found at different locations between the name, orderid and shipdate elements.
- There's no "pre" element. I think Ramesh wanted preformat the XML document.
- There's a space between the element name and its content type
Here is the whole document with DTD.
 
Sridhar Kilambi
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Valentin for the clarification .
regards
sridhar
------------------------------------------
aspirant for xml 141 cert.
[ December 30, 2002: Message edited by: Sridhar Kilambi ]
 
Syed AliRaza Zaidi
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Valentin,
Yes Valentin good job yours is the correct one I was thinking about using * but I left out Thanks for correcting me by the way.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
Happy to help
 
Ramesh Balasubramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for all your response, Especially to
Valentin Crettaz. .
Actually my doubt was for the #PCDATA appearing in between each tag.
My understanding is
* means, the one mentioned in "(" to ")" can
appear 0 to n times.
And "(#PCDATA | name | orderid | shipdate)"
implies that any one of them
can appear. i.e. #PCDATA or name or
orderid or shipdate in an
XML instance.

Can you please explain.
Thx.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
( a | b | c)* means that any one of a, b or c can appear any number of times, that is, all the following productions are valid:
aaa
abc
aabac
abbbb
c
b
ab
ac
...
Does this clear your doubts?
Please see the following section of the DTD specification which explains how mixed content can be specified:
DTD Spec - Mixed content
 
Ramesh Balasubramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all thanks for such a quick reply.
Question:
I) Just (a|b|c)
Does this mean it can have
a
b
c
Can it also have
ab
ac
bc
Can it have in reverse order like
ba
ca
cb
II) For (a|b|c)*
Are these valid?
c
ccb
ccbccbbaac
...
Does that mean that "a" or "b" or "c" can appear any number of times in any order?
Thx for your patience
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The valid productions in the first case, i.e. (a | b | c) are:
a
b
c
<nothing>
The valid productions in the second case, i.e. (a | b | c)* are:
any combinations (actually an infinity of possibilities) of a, b and c plus the empty production
 
Ramesh Balasubramanian
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Valentin Crettaz.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't (a | b | c) mean you must have exactly one of a, b, or c? Empty isn't allowed.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess you are right, Ron. Sorry about that
I must need a break
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you want "a, b, c, or nothing" you would say
(a | b | c)?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic