Win a copy of Succeeding with AI 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
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Schema for DTD with mixed content

 
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?
 
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 ]
 
Beauty is in the eye of the tiny ad.
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic