Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Advice on ways to extend a type using XSD

Reply
Thread Tools

Advice on ways to extend a type using XSD

 
 
Charles Fineman
Guest
Posts: n/a
 
      02-24-2004
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?

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-25-2004


Charles Fineman wrote:

> 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.

--

Martin Honnen
http://JavaScript.FAQTs.com/

 
Reply With Quote
 
 
 
 
Charles Fineman
Guest
Posts: n/a
 
      02-25-2004
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).

Martin Honnen wrote:

>
>
> Charles Fineman wrote:
>
>> 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:
>>
>> .... EDITED OUT ....
>>
>> 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.
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSD type derived via restriction in same namespace as restricted type? burkley@gmail.com XML 7 09-18-2007 01:51 PM
XSD: ways to deal with conditionals on attribute value? Piper707@hotmail.com XML 1 12-30-2005 09:10 PM
XSD: ways of restricting xml to non-empty tags? Piper707@hotmail.com XML 1 12-21-2005 11:33 AM
XML + XSD: Is it possible to get all errors against the XSD? Markus Java 1 11-22-2005 02:53 PM
XSD document for XSD defintion Rick Razzano XML 1 09-26-2003 12:41 AM



Advertisments