#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    USA
    Posts
    830
    Rep Power
    14

    Redeclaring attribute in derived type (XML schema structure)


    This is a question about schema structure.

    Can I redeclare an attribute when deriving a complexType? For example, if I want to create a generic type that specifies a minimal content model and one or more attributes and I want to derive other types from that, adding to the content model. and restricting the value of an attribute of the base type by setting a fixed or default value or restricting the value, etc. e.g.

    Code:
    ...
    
    <xsd:complexType name="BaseType">
    
      <xsd:sequence>
    
        <xsd:element ref="JMM:someElementABC" />
    
      </xsd:sequence>
    
      <xsd:attribute name="id" type="xsd:ID" />
    
    </xsd:complexType>
    
    
    <xsd:complexType name="DerivedType">
    
      <xsd:complexContent>
    
        <xsd:extension base="JMM:BaseType">
    
          <xsd:sequence>
    
            <xsd:element ref="JMM:someElementXYZ" />
    
          </xsd:sequence>
    
          <xsd:attribute name="id" type="xsd:ID" fixed="Derived" />
    
        </xsd:extension>
    
      </xsd:complexContent>
    
    </xsd:complexType>
    
    ...
    The spec seems to rule this out, but it would provide a useful facility for me, and the XSV schema validator linked from the W3C schema page doesn't seem to have a problem with it.

    Relevant parts of the spec:


    Complex Type Definition with simple content Schema Component

    {attribute uses}

    A union of sets of attribute uses as follows
    1 The set of attribute uses corresponding to the <attribute> [children], if any.
    ...
    3 if the type definition ·resolved· to by the ·actual value· of the base [attribute] is a complex type definition, the {attribute uses} of that type definition, ...

    3.4.6 Constraints on Complex Type Definition Schema Components

    Schema Component Constraint: Complex Type Definition Properties Correct

    All of the following must be true:

    ...
    4 Two distinct attribute declarations in the {attribute uses} must not have identical {name}s and {target namespace}s.
    ...

    What do you make of this?

    --> Jesse
  2. #2
  3. No Profile Picture
    Python Prophet
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Amersfoort, The Netherlands
    Posts
    45
    Rep Power
    13
    I'm not sure, and I can't find it in my favourite XML Schema guide. I don't have much time now, but I'll check some more later.

    I think it's allowed because you're in an extension. You override the old attribute with this. Identical names are of course not allowed if they're in the same section.
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems. - Jamie Zawinski, in comp.lang.emacs
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    USA
    Posts
    830
    Rep Power
    14

    I think it's allowed because you're in an extension. You override the old attribute with this. Identical names are of course not allowed if they're in the same section.
    I don't think that's correct because (refer to the excerpts from the spec in my original post) the constraint applies to the attribute uses, and the attribute uses for the derived type includes the attribute uses of the base type, which include any <attribute> children of the base type.

    If you do have the chance to look into it, I would appreciate it. I'm also trying to get to the bottom of this on xmlschema-dev@w3.org. The spec seems to spell it out pretty clearly that you can't do it, but it seems extremely limiting, and you know how those W3C specs are -- and the schema spec is a beast.

    --> Jesse
  6. #4
  7. No Profile Picture
    Python Prophet
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Amersfoort, The Netherlands
    Posts
    45
    Rep Power
    13
    Originally posted by JMM


    I don't think that's correct because (refer to the excerpts from the spec in my original post) the constraint applies to the attribute uses, and the attribute uses for the derived type includes the attribute uses of the base type, which include any <attribute> children of the base type.

    If you do have the chance to look into it, I would appreciate it. I'm also trying to get to the bottom of this on xmlschema-dev@w3.org. The spec seems to spell it out pretty clearly that you can't do it, but it seems extremely limiting, and you know how those W3C specs are -- and the schema spec is a beast.

    --> Jesse
    I saw your post there and the reply by Jeni, and I'm not so sure, I can't find the answer anywhere. I have asked another guy(always well informed about XML and the surrounding technologies), and he's also looking into it.
    Some people, when confronted with a problem, think “I know, I'll use regular expressions.” Now they have two problems. - Jamie Zawinski, in comp.lang.emacs
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    USA
    Posts
    830
    Rep Power
    14
    OK, thanks Taradino. Hopefully we can figure this out. I'm not saying she's wrong, but I'm not confident that Jeni's answer was right -- if you can't redeclare an attribute then I think she's wrong about being able to do it in two steps, and if you can I think she's wrong about having to do it in two steps, but like I said, I'm not certain, so I'll be interested to hear what some other people think. I'm pretty disappointed in the (so far) underwhelming response on xmlschema-dev, but we'll see what happens.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2001
    Location
    USA
    Posts
    830
    Rep Power
    14
    OK. Jeni was right. To make a long story short: when deriving from a complex type by restriction, any attribute use of the base type that has the same name and target namespace as an attribute child of <restriction> in the derived type is overridden.

    As an aside, also pointed out by Jeni, you can't set a default or fixed value for an attribute of or derived from type ID as I did in my example.

IMN logo majestic logo threadwatch logo seochat tools logo