Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD Schema question 1

Status
Not open for further replies.

ma77c

Programmer
Jan 27, 2006
28
CA
I'm new to XML and from what I've gathered so far, I'm under the impression that XML Schemas are supposed to be somewhat superior or prefered over DTDs. However, I'm having trouble with one thing.

Is there a way to achieve the same effect as this DTD statement with Schema notation?

Code:
<!ELEMENT a (b | c | d)*>

Appreciate the help. Thanks!
 
I have actually gone through that tutorial and I believe the answer to my question to be along the lines of:

Code:
<xs:element name="a">
	<xs:complexType>
		<xs:all>
			<xs:element name="b" type=".." minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="c" type=".." minOccurs="0" maxOccurs="unbounded"/>
			<xs:element name="d" type=".." minOccurs="0" maxOccurs="unbounded"/>
		</xs:all>
	</xs:complexType>
</xs:element>

My problem lies in that, as it states in the tutorial, maxOccurs can only be set to 1. Could you please point out what I am missing?
 
Well, I am really out of my comfort zone here, but I think you might consider something like:
Code:
<xs:element name="a">
    <xs:complexType>
        <xs:all minOccurs="0" maxOccurs="unbounded">
            <xs:element name="b" type=".." />
            <xs:element name="c" type=".." />
            <xs:element name="d" type=".." />
        </xs:all>
    </xs:complexType>
</xs:element>

Tom Morrison
 
Hmm... I appreciate the effort Tom, I truly thought you had it, but XMLSpy is still giving me an error:

Value 'unbounded' of attribute maxOccurs does not match simple type '{no name}'.

And if I change maxOccurs to 1, the file is valid. I'm stumped...
 
Maybe try this?
[tt]
<xs:element name="a">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbound">
<xs:element ref="b" />
<xs:element ref="c" />
<xs:element ref="d" />
</xs:choice>
</xs:complexType>
</xs:element>
[/tt]

 
Success! Much appreciated tsuji. Thanks everyone!
 
Thanks for the vote! Just remain to correct a typo, so frustrating! By "unbound", I sure meant "unbounded". The corresponding line should be read like this.
[tt] <xs:choice minOccurs="0" maxOccurs="unbound[red]ed[/red]">[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top