Hi Octavian,
   Here are some more thoughts, about this bug report.

You've specified the attribute declaration, <xs:attribute name="lang"
inheritable="true" type="xs:string"/> within two different complex
type definitions ("enType" and "frType"), and then say that this
attribute is inheritable. I feel, this is an incorrect modelling of
inheritable attribute in the schema.

For an attribute to be inheritable, all references to it in an XML
instance document should originate from the same complex type
definition (this is necessary, to ensure a common identity of an
inheritable attribute).

I would propose the following schema document for this use case (one
of the various, I believe):
(this one works fine, with our current implementation)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
elementFormDefault="qualified">

     <xs:element name="BookStore">
           <xs:complexType>
                <xs:sequence>
                     <xs:element ref="Book" maxOccurs="unbounded"/>
                 </xs:sequence>
           </xs:complexType>
      </xs:element>

      <xs:element name="Book" type="AbstractBook">
           <xs:alternative test="@lang='en'" type="enType"/>
           <xs:alternative test="@lang='fr'" type="frType"/>
           <xs:alternative type="enType"/>
      </xs:element>

      <xs:element name="Author">
           <xs:alternative test="@lang='en'" type="enAuthorType"/>
           <xs:alternative test="@lang='fr'" type="frAuthorType"/>
           <xs:alternative type="enAuthorType"/>
      </xs:element>
        
      <xs:complexType name="enType">
            <xs:complexContent>
                 <xs:restriction base="AbstractBook">
                     <xs:sequence>
                         <xs:element name="TitleEn" type="xs:string"/>
                         <xs:element ref="Author"/>
                     </xs:sequence>
                </xs:restriction>
            </xs:complexContent>
      </xs:complexType>

      <xs:complexType name="frType">
           <xs:complexContent>
                <xs:restriction base="AbstractBook">
                    <xs:sequence>
                        <xs:element name="TitleFr" type="xs:string"/>
                        <xs:element ref="Author"/>
                    </xs:sequence>
                </xs:restriction>
           </xs:complexContent>
      </xs:complexType>
        
      <xs:complexType name="AbstractBook" abstract="true">
            <xs:sequence>
                 <xs:any processContents="skip" minOccurs="0" 
maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="lang" inheritable="true" type="xs:string"/>
      </xs:complexType>

      <xs:complexType name="enAuthorType">
            <xs:sequence>
                <xs:element name="NameEn" type="xs:string"/>
            </xs:sequence>
      </xs:complexType>

      <xs:complexType name="frAuthorType">
            <xs:sequence>
                 <xs:element name="NameFr" type="xs:string"/>
            </xs:sequence>
      </xs:complexType>

</xs:schema>

Here are rationale for this modified schema design:
There is an abstract complex type "AbstractBook" which declares an
attribute to be inheritable. From this schema type, two other types
are derived ("enType" and "frType"). Now, all references to an
inheritable attribute in an XML instance document get validated by the
same attribute declaration (which is declared to be inheritable). This
seems a necessary and logical schema model to me.

Therefore, I would think that your bug report may be incorrect. I
haven't cross checked the above suggested rationale with the XSD 1.1
spec (I'll do that in due course. In the meantime, comments from
others are welcome).

On Tue, Oct 9, 2012 at 5:50 PM, Octavian Nadolu (JIRA)
<[email protected]> wrote:
>
>      [ 
> https://issues.apache.org/jira/browse/XERCESJ-1590?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
>  ]
>
> Octavian Nadolu updated XERCESJ-1590:
> -------------------------------------
>
>     Summary: Alternative type is not detected correctly  (was: Alternative 
> type is not detected corectly)
>
>> Alternative type is not detected correctly
>> ------------------------------------------
>>
>>                 Key: XERCESJ-1590
>>                 URL: https://issues.apache.org/jira/browse/XERCESJ-1590
>>             Project: Xerces2-J
>>          Issue Type: Bug
>>          Components: XML Schema 1.1 Structures
>>    Affects Versions: 2.11.0
>>            Reporter: Octavian Nadolu
>>            Priority: Trivial
>>
>> When I validate the following xml document with the associated schema, I get 
>> the error: cvc-complex-type.2.4.a: Invalid content was found starting with 
>> element 'NameFr'. One of '{NameEn}' is expected.
>> There should be no error because the lang attribute is inheritable, and the 
>> Author element type should be frAuthorType.
>> I tested on the xml-schema-1.1-dev branch.
>> ----------XML Document-----------------
>> <BookStore xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
>> xsi:noNamespaceSchemaLocation="schema.xsd">
>>     <Book lang="fr">
>>         <TitleFr></TitleFr>
>>         <Author>
>>             <NameFr></NameFr>
>>         </Author>
>>     </Book>
>> </BookStore>
>> -----------------------------------------------------
>> -------------- schema.xsd -----------------------
>> <?xml version="1.0" encoding="UTF-8"?>
>> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; 
>> elementFormDefault="qualified">
>>     <xs:element name="BookStore">
>>         <xs:complexType>
>>             <xs:sequence>
>>                 <xs:element ref="Book" maxOccurs="unbounded"/>
>>             </xs:sequence>
>>         </xs:complexType>
>>     </xs:element>
>>
>>     <xs:element name="Book">
>>         <xs:alternative test="@lang='en'" type="enType"/>
>>         <xs:alternative test="@lang='fr'" type="frType"/>
>>     </xs:element>
>>
>>     <xs:element name="Author">
>>         <xs:alternative test="@lang='en'" type="enAuthorType"/>
>>         <xs:alternative test="@lang='fr'" type="frAuthorType"/>
>>         <xs:alternative type="enAuthorType"/>
>>     </xs:element>
>>
>>     <xs:complexType name="enType">
>>         <xs:sequence>
>>             <xs:element name="TitleEn" type="xs:string"/>
>>             <xs:element ref="Author"/>
>>         </xs:sequence>
>>         <xs:attribute name="lang" inheritable="true" type="xs:string"/>
>>     </xs:complexType>
>>
>>     <xs:complexType name="frType">
>>         <xs:sequence>
>>             <xs:element name="TitleFr" type="xs:string"/>
>>             <xs:element ref="Author"/>
>>         </xs:sequence>
>>         <xs:attribute name="lang" inheritable="true" type="xs:string"/>
>>     </xs:complexType>
>>
>>     <xs:complexType name="enAuthorType">
>>         <xs:sequence>
>>             <xs:element name="NameEn" type="xs:string"/>
>>         </xs:sequence>
>>     </xs:complexType>
>>
>>     <xs:complexType name="frAuthorType">
>>         <xs:sequence>
>>             <xs:element name="NameFr" type="xs:string"/>
>>         </xs:sequence>
>>     </xs:complexType>
>> </xs:schema>




-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to