Skip to content

Instantly share code, notes, and snippets.

@torstenwerner
Created February 1, 2017 15:37
Show Gist options
  • Save torstenwerner/ccb7f1cfc330195904436d2ff1b90551 to your computer and use it in GitHub Desktop.
Save torstenwerner/ccb7f1cfc330195904436d2ff1b90551 to your computer and use it in GitHub Desktop.
/**
* Xsd 1.1 validation with a pimped xerces2 jar.
*/
@Grapes(
@Grab(group = 'com.rackspace.apache', module = 'xerces2-xsd11', version = '2.11.2')
)
import javax.xml.transform.stream.StreamSource
import javax.xml.validation.SchemaFactory
def schemaName = 'choice-xs11.xsd'
def instanceName = 'instance-xs11.xml'
def schemaDocument = new StreamSource(new FileInputStream(schemaName))
def instanceDocument = new StreamSource(new FileInputStream(instanceName))
def factory = SchemaFactory.newInstance("http://www.w3.org/XML/XMLSchema/v1.1")
def schema = factory.newSchema(schemaDocument)
def validator = schema.newValidator()
validator.validate(instanceDocument)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment