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 2:07:00 AM On 1 Feb, 07:49, Pavel Lepin <p.le...@ctncorp.com> wrote: > mnicke...@gmail.com <mnicke...@gmail.com> wrote in > <f0461272-9799-42a5-a909-1673f4256...@d70g2000hsb.googlegroups.com>: > > > I'm still learning, so apologies if this is trivial... > > ... > > > <Record> > > =A0 =A0<foo id=3D"a">... </foo> > > =A0 =A0<foo id=3D"b">....</foo> > > =A0 =A0<foo id=3D"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 )? > > It is possible. > =2E.. > =A0 <xs:element name=3D"foo"> > =A0 =A0 <xs:complexType> > =A0 =A0 =A0 <xs:simpleContent> > =A0 =A0 =A0 =A0 <xs:extension base=3D"xs:string"> > =A0 =A0 =A0 =A0 =A0 <xs:attribute ref=3D"id" use=3D"required"/> > =A0 =A0 =A0 =A0 </xs:extension> > =A0 =A0 =A0 </xs:simpleContent> > =A0 =A0 </xs:complexType> > =A0 </xs:element> > =A0 <xs:attribute name=3D"id"> > =A0 =A0 <xs:simpleType> > =A0 =A0 =A0 <xs:restriction base=3D"xs:string"> > =A0 =A0 =A0 =A0 <xs:pattern value=3D"(a|b|c)"/> > =A0 =A0 =A0 </xs:restriction> > =A0 =A0 </xs:simpleType> > =A0 </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. 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. For example, as we all know, a simple way to make an XML instance namespace qualified is to use the default namespace (xmlns=3D"foo"), and that could potentially be a simple localized fix. But unqualified attributes always belong to no namespace, so this wouldn't fix the attributes, and a more detailed fix-up would be required. Just my thought - and I'd interested to hear others! Pete Cordell Codalogic Visit http://www.codalogic.com/lmx/ for XML C++ data binding | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
