Ciao, sto provando a validare in java una request XML onvif.
La request è questa:
codice:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:wsa5="http://www.w3.org/2005/08/addressing">
<SOAP-ENV:Body>
<tds:GetCapabilities>
<tds:Category>All</tds:Category>
</tds:GetCapabilities>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
e il codice java che sto usando è questo:
codice:
ClassPathResource resource = new ClassPathResource("onvif.xsd");
byte[] fileData = FileCopyUtils.copyToByteArray(resource.getInputStream());
String fileContent = new String(fileData, "UTF-8");
SchemaTypeLoader loader = XmlBeans.typeLoaderForClassLoader(getClass().getClassLoader()); XmlObject schema = loader.parse(fileContent, null, null);
XmlObject xml = XmlObject.Factory.parse(xmlToCheck);
ArrayList validationErrors = new ArrayList(); XmlOptions validationOptions = new XmlOptions(); validationOptions.setDocumentType(schema.schemaType()); validationOptions.setErrorListener(validationErrors);
boolean isValid = xml.validate(validationOptions);
la validate() torna false con questo errore error: cvc-elt.1: Invalid type
Qui trovate i files dello schema https://github.com/onvif/specs/tree/...l/ver10/schema
Grazie a chi risponderà