How to define XSD to allow any XML element as child element

While working on a new feature for WSO2 GREG i came across a requirement  to allow any arbitrary XML element to be passed as a child element and i needed to define this in an XSD file. After a bit of searching and some help i was able to find the correct XSD structure for this and thought i might be helpful to share it

<xs:element maxoccurs="unbounded" minoccurs="0" name="parameter">
    <xs:complextype>
 <xs:sequence>
     <xs:any maxoccurs="unbounded" minoccurs="0" processcontents="skip">
 </xs:any></xs:sequence>
        <xs:attribute name="name" type="xs:string" use="optional">
        <xs:attribute name="value" type="xs:string" use="optional">
    </xs:attribute></xs:attribute></xs:complextype>
</xs:element>

The given XSD will allow an XML such as the example given below

<parameter name="payload">
 <p:adderprocessrequest xmlns:p="http://wso2.org/bps/sample">
  <!--Exactly 1 occurrence -->
  <x xmlns="http://wso2.org/bps/sample">x</x>
  <!--Exactly 1 occurrence -->
  <y xmlns="http://wso2.org/bps/sample">y</y>
 </p:adderprocessrequest>
</parameter>
Hope this is helpful to anyone who needs to to configure an XSD for a similar situation

Popular posts from this blog

Writing Unit Tests to test JMS Queue listener code with ActiveMQ

How to set up a Apache Spark cluster in your local machine

Apache Hadoop MapReduce - Detailed word count example from scratch