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

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

  1. nbulchandani

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

  2. 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, Jan 3, 2013
    #2
    1. Advertisements

  3. nbulchandani

    nbulchandani Guest

    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.
     
    nbulchandani, Jan 4, 2013
    #3
  4. 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, Jan 4, 2013
    #4
  5. nbulchandani

    nbulchandani Guest

    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.
     
    nbulchandani, Jan 7, 2013
    #5
  6. 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, Jan 7, 2013
    #6
  7. nbulchandani

    nbulchandani Guest

    nbulchandani, Jan 8, 2013
    #7
  8. Sun, 6 Jan 2013 20:28:12 -0800 (PST), //:
    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 Stamenkov, Jan 12, 2013
    #8
  9. nbulchandani

    cmsmcq Guest

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

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 (here). After that, you can post your question and our members will help you out.