2011-10-14 95 views

回答

8

不能與XmlSlurperXmlParser沒有,但你可以still call the standard Java way from Groovy

代碼調整和從該鏈接粘貼在這裏:

import javax.xml.XMLConstants 
import javax.xml.transform.stream.StreamSource 
import javax.xml.validation.SchemaFactory 

String xmlString = ''' ... your xml ... ''' 
String xsdString = ''' ... your xsd ... ''' 

def factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI) 
def schema = factory.newSchema(new StreamSource(new StringReader(xsdString))) 
def validator = schema.newValidator() 
validator.validate(new StreamSource(new StringReader(xmlString)))