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!

need help with meaning of this schema

Status
Not open for further replies.

cat5ive

MIS
Dec 3, 2004
184
US
Hi,

I'm trying to learn xml schema. Is the code below mean element billOfLading can contain either element masterBill or houseBill but not both? How can I modify it so that it can contain either masterBill or houseBill or both.
And at lease one of them (masterBill or houseBill) must be present in billOfLading.
Thank in advance

Code:
<xs:complexType name="data">
<xs:sequence>
<xs:element name="actionCode" type="xs:string">
<xs:element name="billOfLading" type="bl" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>

<xs:complexType name="bl">
<xs:sequence>
<xs:choice>
<xs:element name="masterBill" type="mbl"/>
<xs:element name="houseBill" type="hbl"/>
</xs:choice>
</xs:sequence>
</xs:complexType>
 
[1] Q: >Is the code below mean element billOfLading can contain either element masterBill or houseBill but not both?
A: It means that.

[2] Q: >How can I modify it so that it can contain either masterBill or houseBill or both.
[2.1] A1: No specific ordering imposed, plus condition "or none".
[tt]
<xs:complexType name="bl">
<xs:all>
<xs:element name="masterBill" type="mbl" minOccurs="0" />
<xs:element name="houseBill" type="hbl" minOccurs="0" />
</xs:all>
</xs:complexType>
[/tt]
[2.2] A2: With specific ordering that masterBill if exists appears before houseBill, plus condition "or none".
[tt]
<xs:complexType name="bl">
<xs:sequence>
<xs:element name="masterBill" type="mbl" minOccurs="0" />
<xs:element name="houseBill" type="hbl" minOccurs="0" />
</xs:sequence>
</xs:complexType>
[/tt]
[2.3] Q: >And at lease one of them (masterBill or houseBill) must be present in billOfLading.
A: W3C schema language, as expressive as it be, cannot express this condition. One needs alternative to impose that constraint.
 
One more question.
Is it illegal to defind 'type' both in element declaration and inside simpleType, see below.
Code:
      <xs:element name="itemDescription" [COLOR=red]type="xs:string" [/color]minOccurs="0">
		<xs:simpleType>
 		     <xs:restriction [COLOR=red]base="xs:string">[/color]
			<xs:maxLength value="50"/>	
		     </xs:restriction>
	       </xs:simpleType>
	    </xs:element>

When I tried to open the file with software Altova XMLSpy, I got the error message below and the word element is highlighted.
The 'type' attribute and an anonymous type definition are mutually exclusive for element declaration 'itemDescription'.
 
[3] Q: >Is it illegal to defind 'type' both in element declaration and inside simpleType.
A: It is. The point is that with the simpleType contained inside the xs:element tag, you are on the way to define a simple type, anonymous and local to the element. Hence, it is contradictory to the parser being told it is of type xs:string.

[3.1] If you want to define a custom simpleType to be declared in the xs:element tag as an attribute, you can make it named with global in scope. It would be available by then to be referred to in other places in the schema. Like this.
[tt]
<xs:simpleType name="x">
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
<xs:element name="itemDescription" type="[red]x[/red]" minOccurs="0" />
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top