JoshuaP Posted October 26, 2009 Report Share Posted October 26, 2009 (edited) Hi,I want to define a type in my XSD that will validate both the XML examples below. <!-- Example 1 --><my_root_node> <street_type>STREET</street_type></my_root_node> <!-- Example 2 --><my_root_node> <street_type> <street_type>STREET</street_type> <street_type_alias>ST</street_type_alias> </street_type></my_root_node> However I do not want to define a mixed type as I don't want the following XML example to be valid. <!-- XML --><my_root_node> <street_type>STREET <street_type>STREET</street_type> <street_type_alias>ST</street_type_alias> </street_type></my_root_node><!-- XSD --> <xs:complexType name="TYPE_street_type_COMPLEX2" mixed="true"> <xs:complexContent mixed="true"> <xs:restriction base="xs:anyType"> <xs:sequence> <xs:element minOccurs="0" name="street_type" type="xs:string" /> <xs:element minOccurs="0" name="street_type_alias" type="xs:string" /> </xs:sequence> </xs:restriction> </xs:complexContent> </xs:complexType> Also the above example fails when I put <xs:restriction base="xs:string"> which seems odd.ERRMSG: The <complexType> [TYPE_street_type_COMPLEX2], is of Type [http://www.w3.org/2001/XMLSchema:string].'>http://www.w3.org/2001/XMLSchema:string]. However [http://www.w3.org/2001/XMLSchema:string] is not defined as a root item (either a <complexType> or <simpleType>), within this schema or any included or imported schemas.I have tried a union, but this only worked with simple types.I have also thought of other ways to achieve the same thing, like with the example below, but wanted to avoid putting the street_type are an attribute. <my_root_node> <street_type type="STREET"> <street_type_alias>ST</street_type_alias> </street_type></my_root_node> Is there another way to have multiple definitions for one type? I have read some things on this site about substitutions but didn't really understand it. I basically want to join the two following type definitions together. <xs:simpleType name="TYPE_street_type_SIMPLE"> <xs:restriction base="xs:string" /> </xs:simpleType> <xs:complexType name="TYPE_street_type_COMPLEX"> <xs:sequence> <xs:element minOccurs="0" name="street_type" type="xs:string" /> <xs:element minOccurs="0" name="street_type_alias" type="xs:string" /> </xs:sequence> </xs:complexType> Can anyone help?Josh Edited October 27, 2009 by JoshuaP Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now