Hi All!
I used some code found here to validate an xml.
That worked well, but now I had to validate one xml file with two xsd file. I found, that would be simple:
because of
has array parameter. But not.
I got error message: java.lang.RuntimeException: Method: newSchema not matched.
I found a code, how to give multiple parameter, but this is in java:
How can I translate it into B4J?
Thanks in advance
Steven
I used some code found here to validate an xml.
B4X:
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))
B4X:
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))
xsd2.InitializeNewInstance("java.io.File",Array(xsdFile2))
xml.InitializeNewInstance("java.io.File",Array(xmlFile))
Schema = factory.RunMethod("newSchema",Array As Object(xsd2,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))
B4X:
Schema = factory.RunMethod("newSchema",Array As Object(xsd2,xsd))
I got error message: java.lang.RuntimeException: Method: newSchema not matched.
I found a code, how to give multiple parameter, but this is in java:
B4X:
Schema schema = factory().newSchema(new Source[] {
new StreamSource(stream("foo.xsd")),
new StreamSource(stream("Alpha.xsd")),
new StreamSource(stream("Mercury.xsd")),
});
Thanks in advance
Steven