WS - SOAP Response Validation

Mirjana's picture

SOAP Response – validation against XML schema

1.    SOAP Response should be:

<bookstore>
          <book>
                    <title>Harry Potter</title>
                    <author>J K. Rowling</author>
                    <year>2005</year>
                    <price>29.99</price>
          </book>
          <book>
                    <title>Learning XML</title>
                    <author>Erik T. Ray</author>
                    <year>2003</year>
                    <price>39.95</price>
          </book>
</bookstore>
  • Here is one similar XML with namespaces:
<m:bookstore xmlns:m="http://www.webservice.pull_fileOut">
          <m:book>
                    <m:title>Harry Potter</m:title>
                    <m:author>J K. Rowling</m:author>
                    <m:year>2005</m:year>
                    <m:price>29.99</m:price>
          </m:book>
          <m:book>
                    <m:title>Learning XML</m:title>
                    <m:author>Erik T. Ray</m:author>
                    <m:year>2003</m:year>
                    <m:price>39.95</m:price>
          </m:book>
</m:bookstore>
 
2.    XML Schema that describes this response is:
 
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:m="http://www.webservice.pull_fileOut" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.webservice.pull_fileOut" elementFormDefault="qualified" attributeFormDefault="unqualified">
          <xs:element name="bookstore">
                    <xs:complexType>
                              <xs:sequence>
                                        <xs:element ref="m:book" maxOccurs="unbounded"/>
                              </xs:sequence>
                    </xs:complexType>
          </xs:element>
          <xs:element name="book">
                    <xs:complexType>
                              <xs:sequence>
                                        <xs:element ref="m:title"/>
                                        <xs:element ref="m:author"/>
                                        <xs:element ref="m:year"/>
                                        <xs:element ref="m:price"/>
                              </xs:sequence>
                    </xs:complexType>
          </xs:element>
          <xs:element name="title">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
          <xs:element name="author">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
          <xs:element name="year">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
          <xs:element name="price">
                    <xs:simpleType>
                              <xs:restriction base="xs:string"/>
                    </xs:simpleType>
          </xs:element>
</xs:schema>

 3.    Namespace added in namespace.properties file

m = http://www.webservice.pull_fileOut

4.    Process Data with response prepared for returning back to client:

.....
.....
<WebservicesResponseNode>
    <m:bookstore xmlns:m="http://www.webservice.pull_fileOut">
      <m:book>
        <m:title>Harry Potter</m:title>
        <m:author>J K. Rowling</m:author>
        <m:year>2005</m:year>
        <m:price>29.99</m:price>
      </m:book>
      <m:book>
        <m:title>Learning XML</m:title>
        <m:author>Erik T. Ray</m:author>
        <m:year>2003</m:year>
        <m:price>39.95</m:price>
      </m:book>
    </m:bookstore>
  </WebservicesResponseNode>
</ProcessData>

5.    SOAP Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <soapenv:Body>
                    <m:bookstore xmlns:m="http://www.webservice.pull_fileOut">
                              <m:book>
                                        <m:title>Harry Potter</m:title>
                                        <m:author>J K. Rowling</m:author>
                                        <m:year>2005</m:year>
                                        <m:price>29.99</m:price>
                              </m:book>
                              <m:book>
                                        <m:title>Learning XML</m:title>
                                        <m:author>Erik T. Ray</m:author>
                                        <m:year>2003</m:year>
                                        <m:price>39.95</m:price>
                              </m:book>
                    </m:bookstore>
          </soapenv:Body>
</soapenv:Envelope>