I defined xml schema the contains an element called 'field' and an extension to it called 'composite-field'. it is defined as following:
<xs:complexType name="field">
<xs:sequence>
<xs:element name="value" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="composite-Field">
<xs:complexContent>
<xs:extension base="field">
<xs:sequence>
<xs:element name="length" type="xs:integer" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
in order to use it in my XML ut has to be:
<field xsi:type="composite-Field">
<value>enjoy</value>
<length>30</length>
</field>
I don't want my XML users to use schema syntax such as xsi:type=..." "
Therefore my question is: Is there any way to make the syntax of the XML be:
<composite-Field>
<value>enjoy</value>
<length>30</length>
</composite-Field>
so the name of the element will imply its inheritence and wouldn't force the users add type attribute ??
I tried this:
<xs:element name="MyCompositeField" type="composite-field"/>
and then:
<MyCompositeField>
<value>enjoy</value>
<length>30</length>
</MyCompositeField>
but it also didn't pass the XSD schema validation
12/09/2010: In response the suggested answer I refined my question a liitle bit.
The schema looks like that:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xs:element name="general">
<xs:complexType>
<xs:sequence>
<xs:element name="field" type="field" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="field">
<xs:sequence>
<xs:element name="value" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="composite-Field" >
<xs:complexContent>
<xs:extension base="field" >
<xs:sequence>
<xs:element name="length" type="xs:integer" />
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="MyCompositeField" type="composite-Field"/>
</xs:schema>
and the required xml looks like that:
<?xml version="1.0" encoding="UTF-8"?>
<general xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema2.xsd">
<MyCompositeField>
<value>enjoy</value>
<length>30</length>
</MyCompositeField>
</general>
using this combination I get in response the error message:
cvc-complex-type.2.4.a: Invalid content was found starting with element 'MyCompositeField'. One of '{field}' is expected.