Forum Discussion
5 Replies
- StephenCOccasional ContributorIs this script correct
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 node = holder["...xpath..."]
def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
def schema = factory.newSchema(new StreamSource(new FileReader("c:/Temp/test.xsd")))
def validator = schema.newValidator()
validator.validate(new StreamSource(new StringReader(node))
I got "Premature end o file" error - RJanecekRegular Contributorand in which row you have this exception ?
- StephenCOccasional Contributor
RJanecek wrote: and in which row you have this exception ?
When I run script assertion a popup shows up with this error.
The last line is causing it because when I comment it there is no error. - Hi!
Could you please provide the error you are getting.
--
Regards
Erik
SmartBear Sweden - StephenCOccasional ContributorI had to modify code to following:
- get XML usingholder.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)))