June 8, 201213 yr Hi all, inspired by the XML transform found here I created a script to validate a XML against a XSD. Enjoy. Best, Alexander RegisterGroovy( "XMLXSDValidation( xmlString ; xsdString )" ; "import javax.xml.XMLConstants import javax.xml.validation.SchemaFactory import javax.xml.transform.stream.StreamSource if( xmlString == null ) throw new Exception(\"You must supply a pathToXMLFile parameter\"); if( xsdString == null ) throw new Exception(\"You must supply a xsd parameter\"); 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)))" ; "isGui = false" )
June 11, 201213 yr Newbies thanks Alexander, it actually works okay but I find using a robust xml validator is actually, better for a newb like myself especialy with troubleshooting errors.
June 14, 201213 yr Author For debugging I also use an editor, I use it actually in production to validate the xmls before I deliver them.
Create an account or sign in to comment