Forum Discussion

Varthini's avatar
Varthini
Occasional Contributor
10 years ago

Validating response xml against xsd

HI
i want to run a groovy script which will validate the response xml from its respective xsds. Below is the code




import javax.xml.validation.SchemaFactory
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.*
// setup validator
Validator validator;
def url = "WSDL location"
log.info url
URI uri = new URI(url);
InputStream inp = uri.toURL().openStream();
log.info inp
try
{
log.info "started"
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
log.info "started"
StreamSource entitySs = new StreamSource(inp);
log.info entitySs
log.info "started"
Schema schema = factory.newSchema(entitySs);
log.info "started"
assert(schema != null);
validator = schema.newValidator();
}
finally
{
inp.close();
inp = null;
}



def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder(testRunner.testCase.testSteps["testStepName"].testRequest.response.getContentAsXml());



validator.validate(new StreamSource(new StringReader(holder)))




After running this script am getting this error org.xml.sax.SAXParseException: s4s-elt-schema-ns: The namespace of element 'definitions' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'. at line ("Schema schema = factory.newSchema(entitySs);)"

can anyone help on this, its urgent.. Thank you

2 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    If you want to validate the web service response, then it can be validated by Schema Compliance assertion. Is this what you are looking for?
  • Varthini's avatar
    Varthini
    Occasional Contributor
    Yes. I need to validate for one or more response at the same time using groovy script. So I need to clear this error..
    Thanks