pulasthi
pulasthi

Reputation: 1750

How to define XSD to allow any element

I want to define an xsd for a parameter element which will allow me to define the parameter in the following manners

<parameter name="save.type" value="attribute" />

or

<parameter name="payload">
        <p:AdderProcessRequest xmlns:p="http://wso2.org/bps/sample">
            <!--Exactly 1 occurrence -->
            <x xmlns="http://wso2.org/bps/sample">{@xvalue}</x>
            <!--Exactly 1 occurrence -->
            <y xmlns="http://wso2.org/bps/sample">{@yvalue}</y>
        </p:AdderProcessRequest>
</parameter>

In the second approach the xml content within the parameter element is not known beforehand so it can be anything.

The following is the xsd i created but it doesn't seem to work.

<xs:element name="parameter" maxOccurs="unbounded" minOccurs="0">
    <xs:complexType>
        <xs:sequence>
            <xs:any minOccurs="0"/>
        </xs:sequence>
        <xs:attribute type="xs:string" name="name" use="optional"/>
        <xs:attribute type="xs:string" name="value" use="optional"/>
    </xs:complexType>
</xs:element>

Any help with this will be much appreciated. Thanks in advance

Upvotes: 9

Views: 15536

Answers (1)

pulasthi
pulasthi

Reputation: 1750

I was able to figure it out after going through the specs posting it here so someone else might need it :). You have to add processContents="skip" so the content won't be processed.

<xs:element name="parameter" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
    <xs:sequence>
        <xs:any processContents="skip" minOccurs="0"/>
    </xs:sequence>
    <xs:attribute type="xs:string" name="name" use="optional"/>
    <xs:attribute type="xs:string" name="value" use="optional"/>
</xs:complexType>

Upvotes: 29

Related Questions