![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: XML Schema Q: Element with either simpleContent or complexContent [Thread Next] Re: XML Schema Q: Element with either simpleContent or complexContentTo: NULL Date: 8/2/2004 8:34:00 AM Martin Honnen <mahotrash@y...> wrote in message news:<410ba394@o...>... > David Norman wrote: > > > How can I create an xml schema where both of the following documents > > are valid? > > > > <theElement> > > <child>some text</child> > > </theElement> > > > > and > > > > <theElement>1234</theElement> > > > > Basically, <theElement> should either contain a single element <child> > > of a specified type or an integer. > > > If you use > > <?xml version="1.0" encoding="UTF-8"?> > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" > version="1.0"> > > <xs:element name="root"> > <xs:complexType> > <xs:sequence> > <xs:element ref="theElement" maxOccurs="unbounded" /> > </xs:sequence> > </xs:complexType> > </xs:element> > > <xs:element name="theElement"> > <xs:complexType mixed="true"> > <xs:sequence> > <xs:element name="child" type="xs:string" minOccurs="0" /> > </xs:sequence> > </xs:complexType> > </xs:element> > > </xs:schema> > > that is you specify the element to have a complex type where mixed > content is allowed then the following validates: > > <?xml version="1.0" encoding="UTF-8"?> > <root > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:noNamespaceSchemaLocation="test2004073101Xsd.xml"> > <theElement> > <child>some text</child> > </theElement> > <theElement>1234</theElement> > </root> > > However the schema also allows a <theElement> as follows > <theElement>1234<child>Kibology</child>1234</theElement> > > If you want to allow either the simple content of type integer or a > complex content of exactly one child element you would need to have a > union of both types however I think a union is only possible for simple > types. Because of the last possibility, mixed="true" doesn't give me what I want. Thanks, David | ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||
|
