Forum Discussion

Paramanand_Ghod's avatar
Paramanand_Ghod
Contributor
14 years ago

How to do Schema complaince using groovy scripting?

Hi,

I need to validate the schema of an response marked in red color below. Is it possible by groovy scripting.

<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 soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<ns1:executeBOResponse xmlns:ns1="http://webservice.bis.com/">
<result xsi:type="xsd:string"><![CDATA[<GetApplicationDetailsResponse><ApplicationDetails><ReceivedDate>2010-08-13</ReceivedDate><ReceivedTime>09:38</ReceivedTime><ApplicationID>28554</ApplicationID><Reference>121082</Reference><CandidateDetails><ID>17392</ID></CandidateDetails><SubmissionDetails><CommunicationID>9934</CommunicationID><Reference>121083</Reference><Channel>&lt;![CDATA[Email]]&gt;</Channel><Direction>&lt;![CDATA[Inbound]]&gt;</Direction><DocID>38085</DocID><DocReference>121086</DocReference><Status>&lt;![CDATA[Completed]]&gt;</Status><Source>&lt;![CDATA[MPI Website]]&gt;</Source><CommunicationDate>2010-08-13</CommunicationDate><CommunicationTime>09:38</CommunicationTime><UpdatedDate>2010-08-13</UpdatedDate><UpdatedTime>09:38</UpdatedTime><Attachments><DocumentMetaData><ID>38085</ID><Reference>121086</Reference><Status>&lt;![CDATA[Facilitator]]&gt;</Status><Title>&lt;![CDATA[COB TestApplication1]]&gt;</Title><FileName>&lt;![CDATA[App Attachment1]]&gt;</FileName><Format>&lt;![CDATA[application/msword]]&gt;</Format><Type>&lt;![CDATA[Original CV]]&gt;</Type><CreationDate>2010-08-13</CreationDate><CreationTime>09:38</CreationTime><Notes>&lt;![CDATA[Test Application Notes1]]&gt;</Notes></DocumentMetaData><DocumentMetaData><ID>38086</ID><Reference>121087</Reference><Language>&lt;![CDATA[English]]&gt;</Language><Status>&lt;![CDATA[Facilitator]]&gt;</Status><Title>&lt;![CDATA[COB TestApplication2]]&gt;</Title><FileName>&lt;![CDATA[App Attachment2]]&gt;</FileName><Format>&lt;![CDATA[application/msword]]&gt;</Format><Type>&lt;![CDATA[Other]]&gt;</Type><CreationDate>2010-08-13</CreationDate><CreationTime>09:38</CreationTime><Notes>&lt;![CDATA[Test Application Notes2]]&gt;</Notes></DocumentMetaData></Attachments><Notes>&lt;![CDATA[General Notes for Application about the Company]]&gt;</Notes></SubmissionDetails><JobDetails><ID>34706</ID></JobDetails></ApplicationDetails></GetApplicationDetailsResponse>]]></result>
</ns1:executeBOResponse>
</soapenv:Body>
</soapenv:Envelope>


Thanks,
Param

2 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    Yes, this should be possible.

    For example, you could use a script assertion like this:


    import javax.xml.XMLConstants
    import javax.xml.transform.stream.StreamSource
    import javax.xml.validation.SchemaFactory

    //Load the XSD from a file
    def xsd = new File('/path/to/schema.xsd').text

    //Get the XML from the response
    def xmlHolder = new com.eviware.soapui.support.XmlHolder( messageExchange.responseContentAsXml )
    def xml = xmlHolder['//result']

    def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
    def schema = factory.newSchema(new StreamSource(new StringReader(xsd)))
    def validator = schema.newValidator()

    try {
    validator.validate(new StreamSource(new StringReader(xml)))
    } catch( e ) {
    assert false
    }


    Good luck!

    Regards,
    Dain
    eviware.com