Forum Discussion
StephenC
14 years agoOccasional Contributor
I had to modify code to following:
- get XML using
- cast XML to string in StringReader method:
- get XML using
holder.getDomNode(XPath)
- cast XML to string in StringReader method:
validator.validate(new StreamSource(new StringReader(node as String)))
import com.eviware.soapui.support.XmlHolder
import javax.xml.XMLConstants
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory
def holder = new XmlHolder( messageExchange.responseContentAsXml )
holder.namespaces["q1"] = '...'
holder.namespaces["ns1"]= '...'
def XPath = "..."
def node = holder.getDomNode(XPath)
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(new FileReader(pathToXsd)))
def validator = schema.newValidator()
validator.validate(new StreamSource(new StringReader(node as String)))