Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 8th, 2006, 06:15 PM
Amol
Guest
 
Posts: n/a
Default Question about xsd:extension

Hi all,
I have a case where I have a element that can appear under multiple
elements
e.g.
<AppFunctions>
<UseTemplate name="1"/>
<MethodSet name="2">
<UseTemplate name="3" />
<MethodCall name="4" />
</MethodSet>
<MethodSet name="5">
<MethodCall name="6" />
</MethodSet>
<UseTemplate name="7" />
</AppFunctions>

I would like a way to define a root element which has just the
UseTemplate element and then derive 2 elements from it "AppFunctions"
and "MethodSet" which extend it to add further elements to it. This
elements in the derived elements need to unordered and can occur
multiple times. This is what I came up with:

<xs:complexType name="UIElementType">
<xs:choice maxOccurs="unbounded">
<xs:element name="UseTemplate" type="UseTemplateType" minOccurs="0"
maxOccurs="unbounded" />
</xs:choice>
</xs:complexType>

<xs:complexType name="AppFunctionType">
<xs:complexContent>
<xs:extension base="UIElementType">
<xs:choice maxOccurs="unbounded">
<xs:element name="MethodSet" type="MethodSetType"
maxOccurs="unbounded" />
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>

<xs:complexType name="MethodSetType">
<xs:complexContent>
<xs:extension base="UIElementType">
<xs:choice maxOccurs="unbounded">
<xs:element name="MethodCall" type="MethodCallType" minOccurs="0"
maxOccurs="unbounded" />
</xs:choice>
<xs:attribute name="name" type="xs:string" use="required" />
</xs:extension>
</xs:complexContent>
</xs:complexType>

This definition is allowing me mutiple UseTemplate nodes directly under
AppFunctions but once I add a MethodSet node under AppFunctions, it
does not allow any UseTemplates anymore.

Thanx in advance,
Amol.

  #2  
Old March 9th, 2006, 09:45 AM
George Bina
Guest
 
Posts: n/a
Default Re: Question about xsd:extension

Hi,

That is because the content type of the derived type contains a
sequence of the two choices, see 3.2.3 from
http://www.w3.org/TR/xmlschema-1/#key-efm
***
3.2.3 otherwise a pair of mixed or elementOnly (determined as per
clause 3.1.2.1 above) and a particle whose properties are as follows:

{min occurs}
1
{max occurs}
1
{term}
A model group whose {compositor} is sequence and whose {particles}
are the particle of the {content type} of the type definition
·resolved· to by the ·actual value· of the base [attribute]
followed by the ·effective content·.
***

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

  #3  
Old March 9th, 2006, 02:45 PM
Amol
Guest
 
Posts: n/a
Default Re: Question about xsd:extension

Is there any other way to get the behavior where the extension would
behave as a choice rather than sequence. The element I want to
"inherit" occurs under multiple elements so rather than define once
under each I was hoping to define it once in a parent element and
extend all the elements that need it from the parent element.

Thanx, Amol.

  #4  
Old March 10th, 2006, 09:35 AM
George Bina
Guest
 
Posts: n/a
Default Re: Question about xsd:extension

No, In XML Schema the model created by extension is sequence.
On possible approach is to place common content in a named group and
refer to that group from your complex types where you want that common
content.
Another one that will have a behaviour very close to what you want is
to define for instance an abstract element, let's say instruction and
define the content model using references to this element. Then you can
define actual non abstract elements that can substitute instruction.
The instruction element will be basically replaced in this way with a
choice of all the elements from its substiturion group.
Have a look at the XML Schema for XSLT 2.0, there you can find
something like I described above:
http://www.w3.org/TR/xslt20/#schema-for-xslt

Best Regards,
George
---------------------------------------------------------------------
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles