Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Re: Re-using a simple type definition; with enumeration constraint and without enumeration constraint [Thread Next] Re: Re-using a simple type definition; with enumeration constraint and without enumeration constraintTo: NULL Date: 2/1/2008 7:32:00 AM On Feb 1, 4:36=A0am, use...@tech-know-ware.com wrote: > On 30 Jan, 22:35, puvit82 <puvis...@gmail.com> wrote: > > > > > > > My problem is as follows, any advice / suggestion would be greatly > > appreciated: > > > Lets suppose that I have defined a simpleType "addressType" with 3 > > enumeration values (Home, Office, Vacation) that restrict data entry. > > I want to use this simpleType in 2 different unrelated complexType > > definitions, lets call them "personalAddress" and "companyAddress" > > > How will I be able to use "addressType" inside "personalAddress" such > > that the 3 enumeration values are taken into consideration, i.e. data > > entry is restricted to either one of those three enumeration values > > and also use the same "addressType" inside "companyAddress" such that > > the enumeration values are not considered and the user can enter a > > completely different value for addressType (such as "HomeOffice" and > > the schema validates the XML file)? > > > I do not want to create another addressType (one with enumerations and > > one without - and different names) > > > Does anybody think that there is a way to re use the same simple type > > twice; once with the enumeration values and another time without the > > enumeration values? > > One thing you might be able to do is define your addressType to be a > list of types, e.g. in an XML instance it might look like: > > =A0 =A0 addressType=3D"Home Office" > > The XML schema for that would look something like: > > =A0 =A0 <xs:simpleType name=3D"addressType"> > =A0 =A0 =A0 =A0 <xs:list> > =A0 =A0 =A0 =A0 =A0 =A0 <xs:simpleType> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <xs:restriction base=3D"xs:string"> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <xs:enumeration value=3D"Home"/> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <xs:enumeration value=3D"Office"/>= > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <xs:enumeration value=3D"Vacation"= /> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 </xs:restriction> > =A0 =A0 =A0 =A0 =A0 =A0 </xs:simpleType> > =A0 =A0 =A0 =A0 </xs:list> > =A0 =A0 </xs:simpleType> > > or you could make the xs:enumeration 'open' by including an xs:union > of the enumeration and xs:string. =A0However, this does weaken the > amount of validation that can be automatically done. > > HTH, > > Pete Cordell > Codalogic > Visithttp://www.codalogic.com/lmx/for XML C++ data binding- Hide quoted te= xt - > > - Show quoted text - Thanks for the input Pete. I tried what you suggested and put the enumerations into a list and heres what a valid xml instance looks like: <BusinessAddress xsi:noNamespaceSchemaLocation=3D"Untitled2.xml" xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-instance"> <AddressType>Home Office</AddressType> <StringOne>any string</StringOne> </BusinessAddress> I actually wanted to be able to allow something that is outside the set of enumeration values of addressType. Nevermind, I guess this is a failed battle!! .. I'll just have to create duplicate types so that one can validate the data and the other one can allow whatever data. Thanks! Puvit | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
