What is the proper format to define a schema for an xml element which contains Attribute,Sub-elements and Subelements also contains SUB-ELEMENTS
For eg: My xml
<element1 attribute1="hello">
<element-sub1>
<element-sub-sub1 attribute-sub-1="hi"/>
<elementsubsub1>
</element1>
I tried with the following schema
<xs:element name="element1">
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub1" type="xs:anyType" maxOccurs="unbounded"/>
<xs:complexType>
<xs:sequence>
<xs:element name="element-sub-sub1" type="xs:anyType" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="attribute-sub-1" type="xs:string"/>
</xs:complexType>
</xs:sequence>
<xs:attribute name="attribute1" type="xs:string"/>
</xs:complexType>
</xs:element>
But I am getting the following error
The content of 'sequence' must match (annotation?, (element | group | choice | sequence | any)*). A problem was found st
arting at: complexType.
Why am I getting this error? What is the right format to write schema for my requirement?
NOTE
Element “element-sub-sub1” may have text also.
UPDATE 1
<element1 URI="">
<element-sub1>
<element-sub-sub1 Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<element-sub-sub1 Algorithm="http://www.w3.org/TR/1999/REC-xslt-19991116">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:template match="/">
Pan : <xsl:copy-of select="//Pp"/>
MobileNo : <xsl:copy-of select="//Mm"/>
TotalAmount : <xsl:copy-of select="//Total"/>
</xsl:template>
</xsl:stylesheet>
element-sub-sub1
</element-sub1>
</element1>
Firs of all, you can’t have a
type="xs:anyType"attribute and an<xs:complexType>element on the same<xs:element>Secondly, a definition of
<xs:complexType>may only appear immediately inside an<xs:element>or as a global type as a child of<schema>Last, but not least. If you want an element to contain attributes, make its type complex.
As mentioned in the comments, the element allows you to insert any xml element on that position. The validation will pass, no matter if the element is actually valid according to some standard or not. It just has to be well-formed.
If you want to validate the entire stylesheet, use an
xs:importto gain access to the namespace, where xsl stylesheets are defined: http://www.w3.org/XML/2000/04schema-hacking/xslt.xsd and reference the stylesheet or transform element in your xsd.Inside
<xs:element name="sub-sub1>:The choice element allows you to use one of two accepted top tags for an XSL stylesheet,
<stylesheet> or<transform>UPDATE: added the minOccurs, maxOccurs attributes for optional stylesheets/transforms