Forum Discussion
Critical_Softwa
12 years agoOccasional Contributor
Yes, I'm using a script assertion with the following code:
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory
//Load the XSD from a file
def xsdFiles = []
def cfgXSDPath = context.expand( '${#Project#cfgXSDPath}' )
def xsdImport01 = new File( cfgXSDPath + '/' + 'dataAccess.xsd').text
xsdFiles.add(xsdImport01)
def xsdImport02 = new File( cfgXSDPath + '/' + 'emsaBaseTypes.xsd').text
xsdFiles.add(xsdImport02)
def xsd = new File( cfgXSDPath + '/' + 'voyage.xsd').text
xsdFiles.add(xsd)
//Get the XML from the request
def rawRequest = context.expand( '${<request-name>#Request}' )
def xmlHolder = new com.eviware.soapui.support.XmlHolder( rawRequest )
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema((Source[]) xsdFiles.toArray())
def validator = schema.newValidator()
try {
validator.validate(new StreamSource(new StringReader(xmlHolder)))
} catch( e ) {
assert false
}