2011-10-14 61 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)))