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

Discussion in 'XML' started by nbulchandani@gmail.com, Jan 3, 2013.

  1. Guest

    <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?
     
    , Jan 3, 2013
    #1
    1. Advertising

  2. Re: How to Reuse a locally defined element under the Same ParentTag

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


    --

    Martin Honnen --- MVP Data Platform Development
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jan 3, 2013
    #2
    1. Advertising

  3. Guest

    On Thursday, 3 January 2013 15:48:01 UTC+5:30, Martin Honnen wrote:
    > Nikel wrote:
    >
    > > <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.
    >
    >
    >
    >
    >
    > --
    >
    >
    >
    > 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.
     
    , Jan 4, 2013
    #3
  4. Re: How to Reuse a locally defined element under the Same ParentTag

    wrote:

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

    --

    Martin Honnen --- MVP Data Platform Development
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jan 4, 2013
    #4
  5. Guest

    On Friday, 4 January 2013 16:48:05 UTC+5:30, Martin Honnen wrote:
    > Nikel wrote:
    >
    >
    >
    > > 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 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.
     
    , Jan 7, 2013
    #5
  6. Re: How to Reuse a locally defined element under the Same ParentTag

    wrote:

    > But what is the reasoning behind not allowing local elements to be referenced in the Local Scope is my actual question.


    Sorry, I don't know that. If no one else answers here you could try the
    mailing list http://www.xml.org/xml-dev/.


    --

    Martin Honnen --- MVP Data Platform Development
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Jan 7, 2013
    #6
  7. Guest

    On Monday, 7 January 2013 18:13:10 UTC+5:30, Martin Honnen wrote:
    > Nikel wrote:
    >
    >
    >
    > > But what is the reasoning behind not allowing local elements to be referenced in the Local Scope is my actual question.

    >
    >
    >
    > Sorry, I don't know that. If no one else answers here you could try the
    >
    > mailing list http://www.xml.org/xml-dev/.
    >
    >
    >
    >
    >
    > --
    >
    >
    >
    > Martin Honnen --- MVP Data Platform Development
    >
    > http://msmvps.com/blogs/martin_honnen/


    Okay , Will Post it there.Thanks!
     
    , Jan 8, 2013
    #7
  8. Re: How to Reuse a locally defined element under the Same ParentTag

    Sun, 6 Jan 2013 20:28:12 -0800 (PST), //:

    > 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)?

    --
    Stanimir
     
    Stanimir Stamenkov, Jan 12, 2013
    #8
  9. Guest

    On Sunday, January 6, 2013 9:28:12 PM UTC-7, wrote:

    > 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).
     
    , Feb 1, 2013
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    5
    Views:
    549
    Steve C. Orr [MVP, MCSD]
    May 17, 2005
  2. Hylander

    To reuse or not to reuse....

    Hylander, Feb 26, 2004, in forum: Java
    Replies:
    0
    Views:
    427
    Hylander
    Feb 26, 2004
  3. shruds
    Replies:
    1
    Views:
    871
    John C. Bollinger
    Jan 27, 2006
  4. code reuse and design reuse

    , Feb 7, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,040
    Malcolm
    Feb 12, 2006
  5. jacob navia

    To reuse or not to reuse

    jacob navia, Nov 5, 2006, in forum: C Programming
    Replies:
    19
    Views:
    543
    Dave Thompson
    Dec 18, 2006
Loading...

Share This Page