I would like to validate this XML:
<meta>
<house>
<big ... />
<little ... />
<big ... />
</house>
<flat>
<red ... />
<red ... />
<yellow ... />
</flat>
</meta>
I wrote that.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meta">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name="house">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name='big' />
<xs:element name='little' />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="flat">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:element name='red'/>
<xs:element name='yellow'/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
But that does not validate my example.
Without 'house' or 'flat', and only meta, that worked.
Where could be my problem ?
Found !
The solution: add a "xs:choice" for each "xs:sequence", like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meta">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name="house">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name='big' />
<xs:element name='little' />
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="flat">
<xs:complexType>
<xs:sequence minOccurs="0" maxOccurs="unbounded">
<xs:choice>
<xs:element name='red'/>
<xs:element name='yellow'/>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Related
I have a following schema (1.1). I would like to have schema that will check that a sequence of parameters has mendatory parameter of type '1' and optional parameter of type '2'. I did it using alternatives because different types have different list of attributes.
How write an assertion to check that parameter of type 1 is mendatory?
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning" elementFormDefault="qualified" vc:minVersion="1.1">
<xs:element name="rule">
<xs:complexType>
<xs:sequence>
<xs:element name="conditions" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="condition" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" maxOccurs="unbounded" minOccurs="1">
<xs:alternative test="#type = '1'" type="typeOne"/>
<xs:alternative test="#type = '2'" type="typeTwo" />
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="typeOne">
<xs:attribute name="type" type="xs:string" use="required"/>
</xs:complexType>
<xs:complexType name="typeTwo">
<xs:attribute name="type" type="xs:string" use="required" />
</xs:complexType>
</xs:schema>
I did it using alternatives because different types have different list of attributes.
It would be like this:
<xs:element name="condition" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="parameter" maxOccurs="unbounded" minOccurs="1">
<xs:alternative test="#type = '1'" type="typeOne"/>
<xs:alternative test="#type = '2'" type="typeTwo" />
</xs:element>
</xs:sequence>
<xs:assert id="type-1-mandatory" test="parameter[#type eq '1']"></xs:assert>
</xs:complexType>
</xs:element>
I have a wsdl that includes a couple of import schema statements, as follows:
<types>
**<xsd:schema>
<xsd:import namespace="http://quickfeedback.ws.cdb.skoda.vwg"
schemaLocation="CDBQuickFeedbackService_schema1.xsd"/>
</xsd:schema>
<xsd:schema>
<xsd:import namespace="http://common.ws.cdb.skoda.vwg"
schemaLocation="CDBQuickFeedbackService_schema2.xsd"/>
</xsd:schema>**
I am using a tool (wsdl2rpg) that will create interfaces into the wsdl, but unfortunately, it does not support/recognise imports. Therefore I need to copy the code from the .xsd into the wsdl.
As a complete newbie to this, I am not sure exactly what code I should copy. Below is schema1, can somebody please advise what I should copy and where to ? I have tried a couple of times, with what I think are logical blocks etc., but they do not seem to work (i.e. the tool still does not pick up the copied code).
<?xml version="1.0" encoding="UTF-8"?><!--Generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, (build IBM 2.2.3-11/25/2013 12:35 PM(foreman)-)
See http://java.sun.com/xml/jaxb --><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://quickfeedback.ws.cdb.skoda.vwg" xmlns:ns1="http://common.ws.cdb.skoda.vwg" version="1.0" targetNamespace="http://quickfeedback.ws.cdb.skoda.vwg">
<xs:import namespace="http://common.ws.cdb.skoda.vwg" schemaLocation="CDBQuickFeedbackService_schema2.xsd"></xs:import>
<xs:element name="GetQuickFeedbackEventsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="BID" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Brand" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Type" type="xs:integer" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetQuickFeedbackEventsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResultSet" type="ns1:ResultSetType" minOccurs="0"></xs:element>
<xs:element name="EventSet" type="tns:QuickFeedbackEventSetType" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetQuickFeedbackResultsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Date" type="xs:date" minOccurs="0"></xs:element>
<xs:element name="BID" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetQuickFeedbackResultsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="QuickFeedbackResultSet" type="tns:QuickFeedbackResultSetType" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersCountRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="RejectionDate" type="xs:date" minOccurs="0"></xs:element>
<xs:element name="BID" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersCountResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResulSet" type="ns1:ResultSetType" minOccurs="0"></xs:element>
<xs:element name="Count" type="xs:int"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="RejectionDate" type="xs:date" minOccurs="0"></xs:element>
<xs:element name="BID" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResulSet" type="ns1:ResultSetType" minOccurs="0"></xs:element>
<xs:element name="DataSet" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Customer" type="tns:GetRejectedAgreementCustomerType" minOccurs="0" maxOccurs="unbounded"></xs:element>
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required"></xs:attribute>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackEventsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="EventSet" type="tns:QuickFeedbackEventSetType"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackEventsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResultSet" type="ns1:ResultSetType" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackResultsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="QuickFeedbackResultSet" type="tns:QuickFeedbackResultSetType" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackResultsResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResultSet" type="ns1:ResultSetType" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="GetRejectedAgreementCustomerType">
<xs:sequence>
<xs:element name="ID" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Email" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Phone" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Details" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Detail" maxOccurs="unbounded">
<xs:complexType>
<xs:complexContent>
<xs:extension base="tns:QuickFeedbackCustomerType">
<xs:sequence>
<xs:element name="Date" type="xs:dateTime"></xs:element>
</xs:sequence>
<xs:attribute name="Number" type="xs:int"></xs:attribute>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Count" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="Cars" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="Car" type="tns:CarType" maxOccurs="unbounded"></xs:element>
</xs:sequence>
<xs:attribute name="Count" type="xs:int"></xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="StudyId" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="Period" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="SurveyNumber" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="DeliveryDate" type="xs:date" minOccurs="0"></xs:element>
<xs:element name="EventType" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="ReturnReason" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="QuestionnaireDate" type="xs:date" minOccurs="0"></xs:element>
</xs:sequence>
<xs:attribute name="Number" type="xs:int"></xs:attribute>
</xs:complexType>
<xs:complexType name="QuickFeedbackCustomerType">
<xs:sequence>
<xs:element name="Salutation" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Firstname" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Lastname" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Email" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Phone" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Street" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="City" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="PostalCode" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Country" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="CarType">
<xs:sequence>
<xs:element name="Brand" type="xs:string"></xs:element>
<xs:element name="VIN" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Model" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="QuickFeedbackEventType">
<xs:sequence>
<xs:element name="StudyId" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="Period" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="SurveyNumber" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="Date" type="xs:dateTime"></xs:element>
<xs:element name="Type" type="xs:integer"></xs:element>
<xs:element name="Customer">
<xs:complexType>
<xs:complexContent>
<xs:extension base="tns:QuickFeedbackCustomerType">
<xs:sequence>
<xs:element name="ID" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="Car" type="tns:CarType"></xs:element>
<xs:element name="Organization" type="tns:OrganizationType" minOccurs="0"></xs:element>
<xs:element name="Importer" type="tns:ImporterType"></xs:element>
<xs:element name="ManualImport" type="xs:integer"></xs:element>
</xs:sequence>
<xs:attribute name="Number" type="xs:int" use="required"></xs:attribute>
</xs:complexType>
<xs:complexType name="OrganizationType">
<xs:sequence>
<xs:element name="Country" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Code" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="EngineerCode" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ImporterType">
<xs:sequence>
<xs:element name="BID" type="xs:string"></xs:element>
<xs:element name="Country" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="QuickFeedbackResultSetType">
<xs:sequence>
<xs:element name="QuickFeedbackResult" type="tns:QuickFeedbackResultType" maxOccurs="unbounded"></xs:element>
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required"></xs:attribute>
</xs:complexType>
<xs:complexType name="QuickFeedbackResultType">
<xs:sequence>
<xs:element name="StudyId" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="Period" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="SurveyNumber" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="DeliveryDate" type="xs:date" minOccurs="0"></xs:element>
<xs:element name="EventType" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="ReturnReason" type="xs:integer" minOccurs="0"></xs:element>
<xs:element name="QuestionnaireDate" type="xs:date" minOccurs="0"></xs:element>
<xs:element name="Customer" type="tns:CustomerIdType"></xs:element>
<xs:element name="BID" type="xs:string"></xs:element>
</xs:sequence>
<xs:attribute name="Number" type="xs:int" use="required"></xs:attribute>
</xs:complexType>
<xs:complexType name="CustomerIdType">
<xs:sequence>
<xs:element name="ID" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Email" type="xs:string" minOccurs="0"></xs:element>
<xs:element name="Phone" type="xs:string" minOccurs="0"></xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="QuickFeedbackEventSetType">
<xs:sequence>
<xs:element name="Event" type="tns:QuickFeedbackEventType" maxOccurs="unbounded"></xs:element>
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required"></xs:attribute>
</xs:complexType>
</xs:schema>
The <types> element may contain zero or various <xsd:schema> elements, and the content of each of those can be either an import of an external xsd file (or more than one) or the schema itself.
Note that in your schema1 you are also importing schema2.xsd
<xs:import namespace="http://common.ws.cdb.skoda.vwg" schemaLocation="CDBQuickFeedbackService_schema2.xsd"></xs:import>
In your case you have two options:
Create two schema elements inside types element
<definitions>
<types>
<xsd:schema>
<!-- content of schema2.xsd -->
</xsd:schema>
<xsd:schema>
<!-- content of schema1.xsd -->
</xsd:schema>
</types>
</definitions>
Create one combined schema element inside types element
This is also a straight-forward solution since you only have to dump the content of both xsd files into an element but you have to pay attention to the namespaces declared.
In schema1 you have these namespaces:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://common.ws.cdb.skoda.vwg"
targetNamespace="http://quickfeedback.ws.cdb.skoda.vwg"
xmlns:tns="http://quickfeedback.ws.cdb.skoda.vwg" >
ns1 was declared so you could use the types from that namespace, which refers to the targetnamespace of schema2.xsd. So if you open schema2.xsd you should see something like this:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://common.ws.cdb.skoda.vwg"
targetNamespace="http://common.ws.cdb.skoda.vwg"
xmlns:tns="http://common.ws.cdb.skoda.vwg" >
But now, since you are combining both schemas into one, you only need one targetnamespace and you already don't need ns1. So your wsdl should look like this:
<definitions>
<types>
<xs:schema targetNamespace="http://quickfeedback.ws.cdb.skoda.vwg" xmlns:tns="http://quickfeedback.ws.cdb.skoda.vwg" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- Here copy the content of schema2.xsd without the <xs:schema>element -->
<xs:element name="GetQuickFeedbackEventsRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="BID" type="xs:string"/>
<xs:element minOccurs="0" name="Brand" type="xs:string"/>
<xs:element minOccurs="0" name="Type" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetQuickFeedbackEventsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ResultSet" type="tns:ResultSetType"/>
<xs:element minOccurs="0" name="EventSet" type="tns:QuickFeedbackEventSetType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetQuickFeedbackResultsRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="Date" type="xs:date"/>
<xs:element minOccurs="0" name="BID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetQuickFeedbackResultsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="QuickFeedbackResultSet" type="tns:QuickFeedbackResultSetType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersCountRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="RejectionDate" type="xs:date"/>
<xs:element minOccurs="0" name="BID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersCountResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ResulSet" type="tns:ResultSetType"/>
<xs:element name="Count" type="xs:int"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="RejectionDate" type="xs:date"/>
<xs:element minOccurs="0" name="BID" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetRejectedAgreementCustomersResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ResulSet" type="tns:ResultSetType"/>
<xs:element minOccurs="0" name="DataSet">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" minOccurs="0" name="Customer" type="tns:GetRejectedAgreementCustomerType"/>
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackEventsRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="EventSet" type="tns:QuickFeedbackEventSetType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackEventsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ResultSet" type="tns:ResultSetType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackResultsRequest">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="QuickFeedbackResultSet" type="tns:QuickFeedbackResultSetType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="InsertQuickFeedbackResultsResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="ResultSet" type="tns:ResultSetType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="GetRejectedAgreementCustomerType">
<xs:sequence>
<xs:element minOccurs="0" name="ID" type="xs:string"/>
<xs:element minOccurs="0" name="Email" type="xs:string"/>
<xs:element minOccurs="0" name="Phone" type="xs:string"/>
<xs:element minOccurs="0" name="Details">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Detail">
<xs:complexType>
<xs:complexContent>
<xs:extension base="tns:QuickFeedbackCustomerType">
<xs:sequence>
<xs:element name="Date" type="xs:dateTime"/>
</xs:sequence>
<xs:attribute name="Number" type="xs:int"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Count" type="xs:int"/>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="Cars">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Car" type="tns:CarType"/>
</xs:sequence>
<xs:attribute name="Count" type="xs:int"/>
</xs:complexType>
</xs:element>
<xs:element minOccurs="0" name="StudyId" type="xs:integer"/>
<xs:element minOccurs="0" name="Period" type="xs:integer"/>
<xs:element minOccurs="0" name="SurveyNumber" type="xs:integer"/>
<xs:element minOccurs="0" name="DeliveryDate" type="xs:date"/>
<xs:element minOccurs="0" name="EventType" type="xs:integer"/>
<xs:element minOccurs="0" name="ReturnReason" type="xs:integer"/>
<xs:element minOccurs="0" name="QuestionnaireDate" type="xs:date"/>
</xs:sequence>
<xs:attribute name="Number" type="xs:int"/>
</xs:complexType>
<xs:complexType name="QuickFeedbackCustomerType">
<xs:sequence>
<xs:element minOccurs="0" name="Salutation" type="xs:string"/>
<xs:element minOccurs="0" name="Firstname" type="xs:string"/>
<xs:element minOccurs="0" name="Lastname" type="xs:string"/>
<xs:element minOccurs="0" name="Email" type="xs:string"/>
<xs:element minOccurs="0" name="Phone" type="xs:string"/>
<xs:element minOccurs="0" name="Street" type="xs:string"/>
<xs:element minOccurs="0" name="City" type="xs:string"/>
<xs:element minOccurs="0" name="PostalCode" type="xs:string"/>
<xs:element minOccurs="0" name="Country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="CarType">
<xs:sequence>
<xs:element name="Brand" type="xs:string"/>
<xs:element minOccurs="0" name="VIN" type="xs:string"/>
<xs:element minOccurs="0" name="Model" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="QuickFeedbackEventType">
<xs:sequence>
<xs:element minOccurs="0" name="StudyId" type="xs:integer"/>
<xs:element minOccurs="0" name="Period" type="xs:integer"/>
<xs:element minOccurs="0" name="SurveyNumber" type="xs:integer"/>
<xs:element name="Date" type="xs:dateTime"/>
<xs:element name="Type" type="xs:integer"/>
<xs:element name="Customer">
<xs:complexType>
<xs:complexContent>
<xs:extension base="tns:QuickFeedbackCustomerType">
<xs:sequence>
<xs:element minOccurs="0" name="ID" type="xs:string"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
<xs:element name="Car" type="tns:CarType"/>
<xs:element minOccurs="0" name="Organization" type="tns:OrganizationType"/>
<xs:element name="Importer" type="tns:ImporterType"/>
<xs:element name="ManualImport" type="xs:integer"/>
</xs:sequence>
<xs:attribute name="Number" type="xs:int" use="required"/>
</xs:complexType>
<xs:complexType name="OrganizationType">
<xs:sequence>
<xs:element minOccurs="0" name="Country" type="xs:string"/>
<xs:element minOccurs="0" name="Code" type="xs:string"/>
<xs:element minOccurs="0" name="EngineerCode" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="ImporterType">
<xs:sequence>
<xs:element name="BID" type="xs:string"/>
<xs:element minOccurs="0" name="Country" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="QuickFeedbackResultSetType">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="QuickFeedbackResult" type="tns:QuickFeedbackResultType"/>
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required"/>
</xs:complexType>
<xs:complexType name="QuickFeedbackResultType">
<xs:sequence>
<xs:element minOccurs="0" name="StudyId" type="xs:integer"/>
<xs:element minOccurs="0" name="Period" type="xs:integer"/>
<xs:element minOccurs="0" name="SurveyNumber" type="xs:integer"/>
<xs:element minOccurs="0" name="DeliveryDate" type="xs:date"/>
<xs:element minOccurs="0" name="EventType" type="xs:integer"/>
<xs:element minOccurs="0" name="ReturnReason" type="xs:integer"/>
<xs:element minOccurs="0" name="QuestionnaireDate" type="xs:date"/>
<xs:element name="Customer" type="tns:CustomerIdType"/>
<xs:element name="BID" type="xs:string"/>
</xs:sequence>
<xs:attribute name="Number" type="xs:int" use="required"/>
</xs:complexType>
<xs:complexType name="CustomerIdType">
<xs:sequence>
<xs:element minOccurs="0" name="ID" type="xs:string"/>
<xs:element minOccurs="0" name="Email" type="xs:string"/>
<xs:element minOccurs="0" name="Phone" type="xs:string"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="QuickFeedbackEventSetType">
<xs:sequence>
<xs:element maxOccurs="unbounded" name="Event" type="tns:QuickFeedbackEventType"/>
</xs:sequence>
<xs:attribute name="Count" type="xs:int" use="required"/>
</xs:complexType>
</xs:schema>
Unless schema2.xsd imports a third schema or it has something special I think this should work.
Just in case you have any issue with the copied content from schema2, note that now in this combined schema you only have one namespace prefix, and that is xs, you already don't have neither xsd nor ns1.
If you get all this headers right, the rest should give you no trouble since it's only a copy-pasted list of <xs:element> and <xs;complexType>.
Hope it helped.
Btw, what are those 2 asterisks in your wsdl before and after <xsd:schema>?
I want to do the validations like:
<A>
<B> or <C>
<D>
</A>
In the , the first element should be one of the B and C. The second element is D. And at the same time, the first element B or C and the second element do not in sequence. It could become and . Anybody know how to do it?
To match your example, please try:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="A">
<xs:complexType>
<xs:sequence>
<xs:choice>
<xs:element name="B" type="xs:string"/>
<xs:element name="C" type="xs:string"/>
</xs:choice>
<xs:element name="D" type="xs:string" minOccurs="0" maxOccurs="1" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
You have to use two things here, the first one is <xs:choice> which allows only one elements to be present in xml.
In order to make an element optional (D) you have to specify minOccurs="0".
Edited (after feedback): All valid cases are covered with this XSD.
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="B" type="xs:string"/>
<xs:element name="C" type="xs:string"/>
<xs:element name="D" type="xs:string"/>
<xs:complexType name="OurType">
<xs:choice>
<xs:sequence>
<xs:element ref="D"/>
<xs:choice>
<xs:element ref="B"/>
<xs:element ref="C"/>
</xs:choice>
</xs:sequence>
<xs:sequence>
<xs:choice>
<xs:element ref="B"/>
<xs:element ref="C"/>
</xs:choice>
<xs:element ref="D"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:element name="A" type="OurType"/>
</xs:schema>
I get the best practice. It should be as below:
<xs:element name="A">
<xs:complexType>
<xs:all>
<xs:element ref="Choice" minOccurs="1" maxOccurs="1"/>
<xs:element ref="D" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="D" type="xs:string"/>
<xs:element name="Choice" abstract="true"/>
<xs:element name="B" substitutionGroup="Choice">
</xs:element>
<xs:element name="C" substitutionGroup="Choice">
</xs:element>
I am trying to map XSD to another XSD that has some different elements in Smooks. When I add both XSDs in Smooks it is not allowing me to map the elements. Is it possible in Smooks to map two different XSDs?
XSD1:CDM
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:RequestResponse="http://example.com/cdm/xsd/Person_01_RequestResponse_001"
xmlns:prsn="http:/example.com/cdm/xsd/Person_01"
attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://example.com/cdm/xsd/Person_01_RequestResponse_001">
<!-- ************ import Employee Model ************ -->
<xs:import namespace="http://example.com/cdm/xsd/Person_01" schemaLocation="Person_01.xsd"/>
<!-- ********************************************* -->
<!-- Request Response Types -->
<!-- ********************************************* -->
<!-- For CreatePerson operation-->
<xs:element name="CreatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonDetail" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CreatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For GetPerson operation-->
<xs:element name="GetPersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonId" type="prsn:PersonIdType" nillable="false"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetPersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person" minOccurs="0" nillable="true"/>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XSD2:LEGACY
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:RequestResponse="http://example.com/xsd/Person_01_RequestResponse_001"
xmlns:prsn="http://example.com/xsd/Person_01"
attributeFormDefault="unqualified" elementFormDefault="qualified"
targetNamespace="http://example.com/xsd/Person_01_RequestResponse_001">
<!-- ************ import Employee Model ************ -->
<xs:import namespace="http://example.com/xsd/Person_01" schemaLocation="Person_01.xsd"/>
<!-- ********************************************* -->
<!-- Request Response Types -->
<!-- ********************************************* -->
<!-- For CreatePerson operation-->
<xs:element name="CreatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="PersonDetail" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="CreatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For GetPerson operation-->
<xs:element name="GetPersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CNIC" type="xs:string" nillable="false" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetPersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person" minOccurs="0" nillable="true"/>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For UpdatePerson operation-->
<xs:element name="UpdatePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="prsn:Person"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="UpdatePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<!-- For deletePerson operation-->
<xs:element name="DeletePersonRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="CNIC" type="xs:string" nillable="false" minOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="DeletePersonResponse">
<xs:complexType>
<xs:sequence>
<xs:element name="ResponseCode" type="xs:string"/>
<xs:element name="ResponseMessage" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Below is the sample xml which has multiple <rulex> that starts with sequence 1 and it can end up to many rule like <rule1> , <rule2>, <rule3> etc....
<?xml version="1.0" encoding="UTF-8"?>
<AddressChange_181>
<rules>
<rule1>
<conditions>xya</conditions>
<response_path>abc</response_path>
</rule1>
<rule2>
<conditions>xxxx</conditions>
<response_path>aaaa</response_path>
</rule2>
<rule3>
<conditions>yyyyy</conditions>
<response_path>ffff</response_path>
</rule3>
<rule4>
<conditions>zzzz</conditions>
<response_path>yyyy</response_path>
</rule4>
<default>
<response_path>uuuuu</response_path>
</default>
</rules>
</AddressChange_181>
Below is the schema where i tried creating dynamic <rulex> element name for the above xml.
when i generate xml from this schema i do not get the same xml format as above xml.
can you please let me know how to create schema with multiple element name that starts with a sequence number.
My requirement is to add more than one rule (<rule1>,<rule2>,<rule3> etc...) in xml file and this xml file should be validated against schema.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="default" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rule">
<xs:complexType>
<xs:simpleContent>
<xs:restriction base="xs:anyType">
<xs:pattern value="rule/d{1,3}"></xs:pattern>
</xs:restriction>
</xs:simpleContent>
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
</xs:schema>
Thanks,
Madhu
There is no way to define such a structure using XSD if the number of ruleX tags is arbitrarily defined. If you can constrain the upper bound to a maximum, and you really have to stick with ruleX naming convention, than you can define a complex type such as ruleType, then a bunch of rule1, rule2,... , ruleN elements of that type - I would call this messy... I wouldn't recommend this.
XSD (with a maximum of 6):
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule1" minOccurs="0"/>
<xs:element ref="rule2" minOccurs="0"/>
<xs:element ref="rule3" minOccurs="0"/>
<xs:element ref="rule4" minOccurs="0"/>
<xs:element ref="rule5" minOccurs="0"/>
<xs:element ref="rule6" minOccurs="0"/>
<xs:element ref="default"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="ruleType">
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
<xs:element name="rule1" type="ruleType"/>
<xs:element name="rule2" type="ruleType"/>
<xs:element name="rule3" type="ruleType"/>
<xs:element name="rule4" type="ruleType"/>
<xs:element name="rule5" type="ruleType"/>
<xs:element name="rule6" type="ruleType"/>
</xs:schema>
Alternatively, you could have a tag named "rule" with a #sequence attribute.
XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="mock_rule_list">
<xs:complexType>
<xs:sequence>
<xs:element ref="rules" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="rules">
<xs:complexType>
<xs:sequence>
<xs:element ref="rule" minOccurs="0" maxOccurs="unbounded"/>
<xs:element ref="default"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="SequenceKey">
<xs:selector xpath="rule"/>
<xs:field xpath="#sequence"/>
</xs:unique>
</xs:element>
<xs:complexType name="ruleType">
<xs:sequence>
<xs:element ref="conditions" minOccurs="1" maxOccurs="1"/>
<xs:element ref="response_path" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
<xs:attribute name="sequence" type="xs:int" use="required"/>
</xs:complexType>
<xs:element name="default">
<xs:complexType>
<xs:sequence>
<xs:element ref="response_path"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="conditions" type="xs:string">
</xs:element>
<xs:element name="response_path" type="xs:string"/>
<xs:element name="rule" type="ruleType"/>
</xs:schema>
Sample XML:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<rule sequence="1">
<conditions>conditions1</conditions>
<response_path>response_path1</response_path>
</rule>
<rule sequence="2">
<conditions>conditions2</conditions>
<response_path>response_path2</response_path>
</rule>
<default>
<response_path>response_path1</response_path>
</default>
</rules>
Or it could also be that one could simply use the index of the <rule/> within the parent collection .