Forum Discussion

marlonumali's avatar
Occasional Contributor
8 years ago

Validate xml response with an xsd file.

I'm searching for a way to validate an XML response in soapui pro using an xsd file:


The XML response I got is below:


<s:Envelope xmlns:s="">
     <GetDataResponse xmlns="">
     <GetDataResult>You entered: 5</GetDataResult>


I'm trying to validate it with an XSD file as:


<?xml version="1.0"?>

   <element name="GetDataResponse" type="GetDataResult"/>

   <element name="GetDataResult" type="string"/>



The groovy script I use is:


import javax.xml.XMLConstants
import javax.xml.validation.SchemaFactory

String response = messageExchange.responseContent

new File( 'C:\\Projects\\WcfServiceAPITest\\WcfServiceAPITest.xsd' ).withReader
{ xsd ->
SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI )
.newSchema( new StreamSource( xsd ) )
.validate( new StreamSource( new StringReader( response ) ) )



but I'm getting the following error:


src-resolve.4.2: Error resolving component 'GetDataResult'. It was detected that 'GetDataResult' is in namespace '', but components
from this namespace are not referenceable from schema document 'null'. If this is the incorrect namespace, perhaps the prefix of 'GetDataResult' needs to be changed.
If this is the correct namespace, then an appropriate 'import' tag should be added to 'null'.


I would appreciate any help from the community. Thank you!

8 Replies

  • nmrao's avatar
    Champion Level 3

    It would be easy to validate using schema compliance assertion which does the same unless you have any custom requirement.