Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML Schema Q: Element with either simpleContent or complexContent

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 7/31/2004 3:50:00 PM

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.



-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent