|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
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: Quote:
Quote:
What do you make of this? --> Jesse |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Quote:
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 |
|
#4
|
|||
|
|||
|
Quote:
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. |
|
#5
|
|||
|
|||
|
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.
|
|
#6
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Redeclaring attribute in derived type (XML schema structure) |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|