Advice on ways to extend a type using XSD

Charles Fineman

Usenet Archive
Joined
Dec 18, 2003
Messages
13
Reaction score
0
Say i've got a type that appears in a request... say it represents a shipment. I want it to contain things like from and to address elements as well as a sequence of the pieces being shipped.

Say the operation is supposed to calculate the cost to ship each piece. I would like the response type to look just like the request type but with a price element under each of the item types. For example:

Request:
<shipment>
<from/>
<to/>
<pieces>
<piece>
<weight>100</weight>
</piece>
<piece>
<weight>5</weight>
</piece>
</pieces>
</shipment>

Response:
<shipment>
<from/>
<to/>
<pieces>
<piece>
<weight>100</weight>
<cost>10.00</cost>
</piece>
<piece>
<weight>5</weight>
<cost>5.00</cost>
</piece>
</pieces>
</shipment>

It would be great if I could easily extend the request type to turn it into the response type but I'm not sure there is an easy way to do that.

Any thoughts?
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
Charles said:
Say i've got a type that appears in a request... say it represents a shipment. I want it to contain things like from and to address elements as well as a sequence of the pieces being shipped.

Say the operation is supposed to calculate the cost to ship each piece. I would like the response type to look just like the request type but with a price element under each of the item types. For example:

Request:
<shipment>
<from/>
<to/>
<pieces>
<piece>
<weight>100</weight>
</piece>
<piece>
<weight>5</weight>
</piece>
</pieces>
</shipment>

Response:
<shipment>
<from/>
<to/>
<pieces>
<piece>
<weight>100</weight>
<cost>10.00</cost>
</piece>
<piece>
<weight>5</weight>
<cost>5.00</cost>
</piece>
</pieces>
</shipment>

It would be great if I could easily extend the request type to turn it into the response type but I'm not sure there is an easy way to do that.

One possible way is to have an element with minOccurs="0":
<xs:element name="pieces">
<xs:complexType>
<xs:sequence>
<xs:element name="piece" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="weight" type="xs:double" />
<xs:element name="cost" minOccurs="0" maxOccurs="1"
type="xs:double" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

That way you can have <weight> and <cost> children or only a <weight> child.
 

Charles Fineman

Usenet Archive
Joined
Dec 18, 2003
Messages
13
Reaction score
0
Agreed, but I'm hoping to keep the typing as "strong" as possible. It's clear that I can extend the immediate children of the type (using xs:extension) but it does not look like I can extend, say, the grandchildren.

I would rather not define a ton of global types just for the purposes of extension (is there a way to create global types that are local to the file?). I could also use groups and just define a completely separate complex type (but that's effectively the same as using extension in this case I believe).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top