• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Schema for DTD with mixed content

 
Sergey Gribok
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I heard a lot of times that schemas are more powerful than DTDs. But I can't build equivalent schema for DTD, containing string
<!ELEMENT A (#PCDATA | B | C)*>
Can anyone explain how to build it?
 
Rakesh Gudur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
You can use the choise xsd element for or conditions. I've generated the following schema to solve your problem:
----------------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="A">
<xs:complexType name="test" mixed="true">
<xs:choice>
<xs:element name="B" minOccurs="0" maxOccurs="unbounded"></xs:element>
<xs:element name="C" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
------------------
This should solve your problem.
Thanks,
Rakesh.
 
Sergey Gribok
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you, Rakesh! I undestand now!
P.S.
Note that there is an inaccuracy in your code.
I must write minOccurs="0" maxOccurs="unbounded"
for <choice> element itself, but not for inner elements.
 
Rakesh Gudur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergey,
I don't think it matters. I checked creating an XML file and it works fine. I could create a file like
<A>
<C/>
<C/>
</A>
So this is what is expected, I guess.
That's okay any way,
Rakesh.
[ June 28, 2002: Message edited by: Rakesh Gudur ]
 
Sergey Gribok
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But you can't create this structure:
<A>
<C/>
<B/>
<C/>
</A>
while the DTD <!ELEMENT A (#PCDATA | B | C)*> allows the structure.
[ July 08, 2002: Message edited by: Sergey Gribok ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic