Forum Discussion
SmartBear_Suppo
Alumni
16 years agoHello,
You could use a Script assertion and do the validation in a Groovy script:
Obviously you'll have to replace the file path to reflect the location of your schema. You'll also probably need to change messageExchange.responseContent if the XML you are asserting is surrounded by other XML, which you could do using XPath. Good luck!
Regards,
Dain
eviware.com
You could use a Script assertion and do the validation in a Groovy script:
import org.apache.xmlbeans.XmlBeans
import org.apache.xmlbeans.XmlObject
import org.apache.xmlbeans.SchemaTypeLoader
def xsd = XmlObject.Factory.parse( new File('d:\\test.xsd').text )
def sts = XmlBeans.compileXsd( ( XmlObject[] )[ xsd ], XmlBeans.getBuiltinTypeSystem(), null );
def stl = XmlBeans.typeLoaderUnion( ( SchemaTypeLoader[] )[ sts, XmlBeans.getBuiltinTypeSystem() ] )
def xml = stl.parse( messageExchange.responseContent, null, null )
assert xml.validate()
Obviously you'll have to replace the file path to reflect the location of your schema. You'll also probably need to change messageExchange.responseContent if the XML you are asserting is surrounded by other XML, which you could do using XPath. Good luck!
Regards,
Dain
eviware.com