Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: Applying Restrictions to XML Attributes >Thread Next - Re: Applying Restrictions to XML Attributes Re: Applying Restrictions to XML AttributesTo: NULL Date: 2/1/2008 12:23:00 PM usenet@t... <usenet@t...> wrote in <8f2742d7-79d0-4c33-bb39-3dcfb92d3362@e...>: > On 1 Feb, 07:49, Pavel Lepin <p.le...@ctncorp.com> wrote: >> mnicke...@gmail.com <mnicke...@gmail.com> wrote: >> > <Record> >> > <foo id="a">... </foo> >> > <foo id="b">....</foo> >> > <foo id="c">.....</foo> >> > </Record> >> >> > Is it possible to create an xsd file that enforces that >> > within the <Record> block there exists exactly three >> > foo tags each containing a different id value (from the >> > enum a, b, and c )? > >> <xs:element name="foo"> >> <xs:complexType> >> <xs:simpleContent> >> <xs:extension base="xs:string"> >> <xs:attribute ref="id" use="required"/> >> </xs:extension> >> </xs:simpleContent> >> </xs:complexType> >> </xs:element> >> <xs:attribute name="id"> >> <xs:simpleType> >> <xs:restriction base="xs:string"> >> <xs:pattern value="(a|b|c)"/> >> </xs:restriction> >> </xs:simpleType> >> </xs:attribute> >> </xs:schema> > > I don't know what other peoples' opinions are, but in > general I think I would avoid doing a ref to an attribute. > My reasoninig is that in XML documents attributes are > generally unqualified (although there are numerous > exceptions to this such as xml:lang etc.). If an XML > namespace is present, then globally defined attributes > are namespace qualified. Agreed, this schema does not > define a targetNamespace, so the issue doesn't arise; at > the moment. Ah well, I don't really have an opinion. I simply don't tinker all that much with schemata, so I'm a bit in the dark as to what the corresponding best practices are. In this case I defined the attribute separately without even thinking twice about this (or the consequences). > However, if as the schema is evolved it's decided to give > it a target namespace, then the attribute will become > qualified. This could potentially make it difficult to > migrate any existing XML instances. Makes sense to me. However, I believe that all newly developed schemata should be namespaced from the start. In that case, the issue would have been immediately obvious anyway. > Just my thought - and I'd interested to hear others! Having thought about it for some five-ten minutes I tend to agree in general. Defining attributes separately and referring to them in element definitions should probably be avoided, unless there's a very good reason for this (like, some sort of meta-information present on many different elements: but in that case it makes perfect sense to namespace the attribute as well, so there). -- <>There is no phenotype</> | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
