| Author |
Schema for DTD with mixed content
|
Sergey Gribok
Greenhorn
Joined: Mar 28, 2002
Posts: 15
|
|
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?
|
Sergey Gribok<br />SCJP,SCWCD,IBM 486,IBM 483,IBM 141
|
 |
Rakesh Gudur
Ranch Hand
Joined: Apr 29, 2002
Posts: 79
|
|
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
Joined: Mar 28, 2002
Posts: 15
|
|
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
Joined: Apr 29, 2002
Posts: 79
|
|
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
Joined: Mar 28, 2002
Posts: 15
|
|
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 ]
|
 |
 |
|
|
subject: Schema for DTD with mixed content
|
|
|