Hello,
I want to validate XML against XSD but I am getting an error
-----------------------------------------------------------------------------------
[Error] SnmAllocateRANGE_Request.xml:3:101: cvc-elt.1: Cannot find the declaration of element 'SOAP-ENV:Envelope'.
-----------------------------------------------------------------------------------
Code :
--------------------------------------------------------------------------------------
public class ModifySnmMaterials {
private static Schema loadSchema(
String xsdFilePath) {
Schema schema = null;
try {
SchemaFactory factory = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schema = factory.newSchema(new File(xsdFilePath));
} catch (Exception e) {
System.out.println(e.getMessage());
}
return schema;
}
public static void main(String[] arg) {
String xsdPath = "C:\\DevelopmentWorkspace\\tnt\\trackntraceserver\\src\\main\\resources\\com\\axway\\tnt\\snm\\SnmQS.xsd";
String xmlPath = "C:\\DevelopmentWorkspace\\tnt\\trackntraceserver\\src\\test\\resources\\com\\axway\\tnt\\test\\snm\\Audit_AllocateRange_WithEmptyReason_ReasonForChangeDisabled\\SnmAllocateRANGE_Request.xml";
Schema schema = loadSchema(xsdPath);
try {
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setValidating(false);
factory.setNamespaceAware(true);
factory.setSchema(schema);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.parse(new File(xmlPath));
} catch (ParserConfigurationException | SAXException | IOException e) {
System.out.println("Validation error" + e.getMessage());
}
}
----------------------------------------------------------------------------------------
Please help me on this issue.
Thanks in advance.
Regards,
Kamal