File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Product and Other Certifications and the fly likes Schema for DTD with mixed content Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Product and Other Certifications
Reply Bookmark "Schema for DTD with mixed content" Watch "Schema for DTD with mixed content" New topic
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 ]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Schema for DTD with mixed content
 
Similar Threads
Question: is this possible in XML?
referencing another xml
DTD for tld & web.xml
DTD vs Schema
Can I have both DTD and schema delcaration for single XML file?