'Static code module
Sub Process_Globals
Private SchemaFactory As JavaObject
Private factory As JavaObject
Private XMLconstants As JavaObject
Private Validator As JavaObject
Private StreamSource As JavaObject
Private xsd,xml As JavaObject
Private Schema As JavaObject
Private ErrorList As List
End Sub
' returns true for valid and false for invalid or IO error
Sub ValidateFile(xsdFile As String,xmlFile As String) As Boolean
ErrorList.Initialize
XMLconstants.InitializeStatic("javax.xml.XMLConstants")
SchemaFactory.InitializeStatic("javax.xml.validation.SchemaFactory")
factory = SchemaFactory.RunMethod("newInstance",Array(XMLconstants.GetField("W3C_XML_SCHEMA_NS_URI")))
xsd.InitializeNewInstance("java.io.File",Array(xsdFile))
xml.InitializeNewInstance("java.io.File",Array(xmlFile))
Schema = factory.RunMethod("newSchema",Array(xsd))
Validator = Schema.RunMethod("newValidator",Null)
StreamSource.InitializeNewInstance("javax.xml.transform.stream.StreamSource",Array(xml))
Validator.RunMethod("setErrorHandler",Array(Validator.CreateEvent("org.xml.sax.ErrorHandler","xmlerr",Null)))
Validator.RunMethod("validate",Array(StreamSource))
If ErrorList.Size > 0 Then
For Each i As Object In ErrorList
Log("Error "&i)
Next
Return False
End If
Return True
End Sub
Sub xmlerr_Event(method As String,args() As Object) As Object
ErrorList.Add(args(0))
Return True
End Sub