particular costraints in mixed contents

J

JU

Hello,
I am pretty new in XML and I'm studying the DTD definition. I cannot
solve a problem, or better, I cannot define what I want in my DTD file.
What I would like to do is that something like
<el>text <child/> text</el>
is accepted but not
<el>text <child/> text<child/></el>

I know that <!ELEMENT el (#PCDATA|child)*> declares the element el as a
mixed content of PCDATA and child but what I want to define is that the
element child occurs exactly once and not more. Instead of PCDATA can
occur either before, after or never. I tried with
(#PCDATA,child+,#PCDATA) but it's not working. Do you know if what I
want is possible? Thanks a lot in advance, and sorry if it's a silly
question. bye!
 
M

Martin Honnen

JU wrote:

I know that <!ELEMENT el (#PCDATA|child)*> declares the element el as a
mixed content of PCDATA and child but what I want to define is that the
element child occurs exactly once and not more. Instead of PCDATA can
occur either before, after or never. I tried with
(#PCDATA,child+,#PCDATA) but it's not working. Do you know if what I
want is possible?

An XML DTD can't do that. An XML XSD schema however could:

<xs:element name="el">
<xs:complexType mixed="true">
<xs:sequence>
<xs:element name="child" />
</xs:sequence>
</xs:complexType>
</xs:element>
 
P

Peter Flynn

JU said:
Hello,
I am pretty new in XML and I'm studying the DTD definition. I cannot
solve a problem, or better, I cannot define what I want in my DTD file.
What I would like to do is that something like
<el>text <child/> text</el>
is accepted but not
<el>text <child/> text<child/></el>

I know that <!ELEMENT el (#PCDATA|child)*> declares the element el as a
mixed content of PCDATA and child but what I want to define is that the
element child occurs exactly once and not more. Instead of PCDATA can
occur either before, after or never. I tried with
(#PCDATA,child+,#PCDATA) but it's not working. Do you know if what I
want is possible?

You can't declare that in XML using a DTD (it would be possible in SGML,
though, but you don't want to go there). If it's essential to use a DTD,
you could use subelements of el, for example

<!ELEMENT el (text,child,text)>
....
<el><text>stuff</text><child/><text>more stuff</text></el>

or use a W3C Schema instead as Martin suggests.

///Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,829
Latest member
PIXThurman

Latest Threads

Top