GdnMaximus
GdnMaximus

Reputation: 47

Create XSD for SOAP Response

I want to create a XSD for validating a SOAP response(XML). However, I am facing the error - "Cannot Find The Declaration Of Element 'soap:Envelope'". I tried adding the soap:Envelope element to XSD and I get this error - "'soap:Envelope' Is Not A Valid Value For 'NCName'".

My XML is below:

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <GetValidOrdersBySalesOppAndLocationResponse xmlns="http://www.webserviceX.NET">
         <GetValidOrdersBySalesOppAndLocationResult>
            <Order>
               <ASV__c>0</ASV__c>
               <Date_Submitted__c>2015-08-25T11:02:07</Date_Submitted__c>
               <Order_Id>1365577</Order_Id>
               <End_Date__c>0001-01-01T00:00:00</End_Date__c>
               <Entitlement_Length__c>0</Entitlement_Length__c>
            </Order>
            <Order>
               <ASV__c>0</ASV__c>
               <Date_Submitted__c>2015-08-24T23:11:19.75</Date_Submitted__c>
               <Order_Id>1365580</Order_Id>
               <End_Date__c>0001-01-01T00:00:00</End_Date__c>
               <Entitlement_Length__c>0</Entitlement_Length__c>
            </Order>
            <Order>
               <ASV__c>0</ASV__c>
               <Date_Submitted__c>2015-08-25T11:19:10</Date_Submitted__c>
               <Order_Id>1365581</Order_Id>
               <End_Date__c>0001-01-01T00:00:00</End_Date__c>
               <Entitlement_Length__c>0</Entitlement_Length__c>
            </Order>
         </GetValidOrdersBySalesOppAndLocationResult>
      </GetValidOrdersBySalesOppAndLocationResponse>
   </soap:Body>
</soap:Envelope>

My XSD is below:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="GetValidOrdersBySalesOppAndLocationResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="GetValidOrdersBySalesOppAndLocationResult">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Order" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:byte" name="ASV__c"/>
                    <xs:element type="xs:dateTime" name="Date_Submitted__c"/>
                    <xs:element type="xs:int" name="Order_Id"/>
                    <xs:element type="xs:dateTime" name="End_Date__c"/>
                    <xs:element type="xs:byte" name="Entitlement_Length__c"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

I used the online XSD generator - http://www.freeformatter.com/xsd-generator.html and Validator - http://www.freeformatter.com/xml-validator-xsd.html.

I also checked out other stackoverflow questions. There is an exact question similar to mine, however it does not have an working solution which can be found here - XSD for soap result not working. I could not comment asking for an update from OP due to my low points. Please help.

UPDATE: Adding an import works!

Working code(Added the second line):

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://www.webserviceX.NET"     xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import namespace="http://schemas.xmlsoap.org/soap/envelope/" schemaLocation="http://schemas.xmlsoap.org/soap/envelope/"/> //Added import
  <xs:element name="GetValidOrdersBySalesOppAndLocationResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="GetValidOrdersBySalesOppAndLocationResult">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="Order" maxOccurs="unbounded" minOccurs="0">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:byte" name="ASV__c"/>
                    <xs:element type="xs:dateTime" name="Date_Submitted__c"/>
                    <xs:element type="xs:int" name="Order_Id"/>
                    <xs:element type="xs:dateTime" name="End_Date__c"/>
                    <xs:element type="xs:byte" name="Entitlement_Length__c"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Upvotes: 2

Views: 11814

Answers (1)

Abel
Abel

Reputation: 57189

You should look into using the original XSD for SOAP envelopes and use that. Then extend with xs:import into your own XSD the necessary datatypes that you want to validate. Using the SOAP XSD will allow you to validate any SOAP request. To validate your own types, just add your own for the generic part.

A better approach is usually to only validate the custom part, as any SOAP compliant service server or client will throw an error if the envelope is not valid SOAP. It also saves you time if you just focus on that part.

Upvotes: 2

Related Questions