Forum Discussion
anallagundla
12 years agoContributor
Try validating ur XSD's hosted in this way
1) Make request
2) Groovy should be used to validate XSD's, by the below groovy script
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.*
// setup validator
Validator validator;
def url = "This should the path where u hosted the xsd file"
log.info url
URI uri = new URI(url);
InputStream inp = uri.toURL().openStream();
try
{
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource entitySs = new StreamSource(inp);
Schema schema = factory.newSchema(entitySs);
assert(schema != null);
validator = schema.newValidator();
}
finally
{
inp.close();
inp = null;
}
def response = context.expand( 'This should be XML response u want to validate against' )
log.info response
validator.validate(new StreamSource(new StringReader(response)))
Let me know if it helps?
Abhinav
1) Make request
2) Groovy should be used to validate XSD's, by the below groovy script
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.*
// setup validator
Validator validator;
def url = "This should the path where u hosted the xsd file"
log.info url
URI uri = new URI(url);
InputStream inp = uri.toURL().openStream();
try
{
SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
StreamSource entitySs = new StreamSource(inp);
Schema schema = factory.newSchema(entitySs);
assert(schema != null);
validator = schema.newValidator();
}
finally
{
inp.close();
inp = null;
}
def response = context.expand( 'This should be XML response u want to validate against' )
log.info response
validator.validate(new StreamSource(new StringReader(response)))
Let me know if it helps?
Abhinav
Related Content
- 12 years agoMitchM