I'm trying to validate xml file using xsd, i've found this code but doesn't work
error in line 22
i've this error :
error in line 22
B4X:
sub test
Dim data_file_Xsd As String = File.ReadString(File.DirAssets,"Schema_VFPR12.xsd")
Dim data_file_xml As String = File.ReadString(File.DirAssets,"test.xml")
ValidateFile(data_file_Xsd,data_file_xml)
end sub
Sub ValidateFile(xsdFile As String,xmlFile As String) As Boolean
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
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 As Object(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
'Technical error report
For a = 0 To ErrorList.Size-2 Step 2
'ptxw.WriteLine(ErrorList.Get(a))
Log(ErrorList.Get(a))
Next
Return False
End If
Return True
End Sub
i've this error :
B4X:
Error occurred on line: 672 (GestFatture)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:132)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:275)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:150)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at anywheresoftware.b4a.keywords.Common$15.run(Common.java:1804)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7626)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:503)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.IllegalArgumentException: http://www.w3.org/2001/XMLSchema
at javax.xml.validation.SchemaFactory.newInstance(SchemaFactory.java:192)
... 21 more
Attachments
Last edited: