How to Reuse a locally defined element under the Same Parent Tag

N

nbulchandani

<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element ref="Size"/>
</xs:sequence>
</xs:complexType>


The element "Size" has local scope , Can't it be reused locally?
 
M

Martin Honnen

<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element ref="Size"/>
</xs:sequence>
</xs:complexType>


The element "Size" has local scope , Can't it be reused locally?

Does

<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size" minOccurs="1" maxOccurs="2">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>

help?

That defines the contents of "Team" as a sequence of one "Name" and two
"Size" elements.

It is not quite clear which content you want to allow, of course
suffices to

<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>

define the contents of "Team" as a sequence of one "Name" and one
"Size", there is no need to reference anything.
 
N

nbulchandani

Does



<xs:complexType name="Team">

<xs:sequence>

<xs:element name="Name" type="xs:string"/>

<xs:element name="Size" minOccurs="1" maxOccurs="2">

<xs:simpleType>

<xs:restriction base="xs:integer">

<xs:totalDigits value="1"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

</xs:sequence>

</xs:complexType>



help?



That defines the contents of "Team" as a sequence of one "Name" and two

"Size" elements.



It is not quite clear which content you want to allow, of course

suffices to



<xs:complexType name="Team">

<xs:sequence>

<xs:element name="Name" type="xs:string"/>

<xs:element name="Size">

<xs:simpleType>

<xs:restriction base="xs:integer">

<xs:totalDigits value="1"/>

</xs:restriction>

</xs:simpleType>

</xs:element>

</xs:sequence>

</xs:complexType>



define the contents of "Team" as a sequence of one "Name" and one

"Size", there is no need to reference anything.





--



Martin Honnen --- MVP Data Platform Development

http://msmvps.com/blogs/martin_honnen/

Well then , Consider this case when both the "Size" elements are not declared closely :

<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="teamLeads">
<xs:complexType>
<xs:sequence>
<xs:element ref="Size"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>


My Question is aren't local elements referenceable in their own Local Scope?In the above case , "Size" is an element declaration local to the root tag"Team" ; then why can't I reuse the Same Declaration using "ref"? Usually , in other Computer Languages , a local element is reusable in the completeLocal Scope.
 
M

Martin Honnen

Well then , Consider this case when both the "Size" elements are not declared closely :

<xs:complexType name="Team">
<xs:sequence>
<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="teamLeads">
<xs:complexType>
<xs:sequence>
<xs:element ref="Size"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>


My Question is aren't local elements referenceable in their own Local Scope?In the above case , "Size" is an element declaration local to the root tag "Team" ; then why can't I reuse the Same Declaration using "ref"? Usually , in other Computer Languages , a local element is reusable in the complete Local Scope.

As far as I understand the schema language you can only reference
globally declared elements (i.e. those declared with xs:element as
direct children of xs:schema).

See http://www.w3.org/TR/xmlschema-1/#cElement_Declarations, it has a
section saying
"the <element> element information item has <complexType> or <group> as
an ancestor and the ref [attribute] is present), the corresponding
schema component is as follows (unless minOccurs=maxOccurs=0, in which
case the item corresponds to no component at all):
Particle Schema Component
Property Representation
{min occurs} The ·actual value· of the minOccurs [attribute], if
present, otherwise 1.
{max occurs} unbounded, if the maxOccurs [attribute] equals unbounded,
otherwise the ·actual value· of the maxOccurs [attribute], if present,
otherwise 1.
{term} The (top-level) element declaration ·resolved· to by the ·actual
value· of the ref [attribute]."

So "_The (top-level) element declaration ·resolved· to by the ·actual
value· of the ref [attribute]._" basically says that reference works
only to top level element declaration (i.e. the ones as direct children
of xs:schema).
 
N

nbulchandani

Nikel wrote:


Well then , Consider this case when both the "Size" elements are not declared closely :

<xs:complexType name="Team">

<xs:element name="Name" type="xs:string"/>
<xs:element name="Size">

<xs:restriction base="xs:integer">
<xs:totalDigits value="1"/>



<xs:element name="teamLeads">


<xs:element ref="Size"/>







My Question is aren't local elements referenceable in their own Local Scope?In the above case , "Size" is an element declaration local to the roottag "Team" ; then why can't I reuse the Same Declaration using "ref"? Usually , in other Computer Languages , a local element is reusable in the complete Local Scope.



As far as I understand the schema language you can only reference

globally declared elements (i.e. those declared with xs:element as

direct children of xs:schema).



See http://www.w3.org/TR/xmlschema-1/#cElement_Declarations, it has a

section saying

"the <element> element information item has <complexType> or <group> as

an ancestor and the ref [attribute] is present), the corresponding

schema component is as follows (unless minOccurs=maxOccurs=0, in which

case the item corresponds to no component at all):

Particle Schema Component

Property Representation

{min occurs} The ·actual value· of the minOccurs [attribute], if

present, otherwise 1.

{max occurs} unbounded, if the maxOccurs [attribute] equals unbounded,

otherwise the ·actual value· of the maxOccurs [attribute], if present,

otherwise 1.

{term} The (top-level) element declaration ·resolved· to by the ·actual

value· of the ref [attribute]."



So "_The (top-level) element declaration ·resolved· to by the ·actual

value· of the ref [attribute]._" basically says that reference works

only to top level element declaration (i.e. the ones as direct children

of xs:schema).



--



Martin Honnen --- MVP Data Platform Development

http://msmvps.com/blogs/martin_honnen/

Okay , I get that. But what is the reasoning behind not allowing local elements to be referenced in the Local Scope is my actual question.
 
S

Stanimir Stamenkov

Sun, 6 Jan 2013 20:28:12 -0800 (PST), /[email protected]/:
Okay , I get that. But what is the reasoning behind not allowing
local elements to be referenced in the Local Scope is my actual
question.

I guess it is as simple as the reason why the global scope
components exists - in order to enable referencing them. How do
imagine referencing a local scope component (which is generally
anonymous)?
 
C

cmsmcq

Okay , I get that. But what is the reasoning behind not allowing local elements to be referenced in the Local Scope is my actual question.

"Reasoning" may be too strong a word for the process that produced this particular bit of XSD 1.0. It was a long time ago, and I have not consulted any of the written records of WG discussion or decisions (so take this with a grain of salt) but my recollection is that the crucial concept, for most members of the XML Schema working group, was not the distinction between local scope and top-level scope but between the "declare in one place, use inanother place" idiom of top-level element declarations and the "define in-line" idiom of local declarations. I do not recall the idea of referring to a local element coming up at all during the design and specification of XSD 1.0. If it had, it might or might not have attracted support; people were quite happy, I think, with the idea that two local element declarationsfor the same name could have different application info, different nullability, etc., and replacing multiple local declarations with a single local declaration and references would seem to stand in the way of that kind of thing.

The topic did come up during the WG's work on XSD 1.1, when specifying thatany element name could be defined at most once in a given scope would havehelped solve some problems that had arisen in the so-called Element Declarations Consistent constraint. But at that time, the WG was unwilling to break backward compatibility with 1.0 in this area (or most others).
 

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
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top