• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Xml validation against xsd in DOM

 
Kamal Verma
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
g tsuji
Ranch Hand
Posts: 689
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-----------------------------------------------------------------------------------
[Error] SnmAllocateRANGE_Request.xml:3:101: cvc-elt.1: Cannot find the declaration of element 'SOAP-ENV:Envelope'.
-----------------------------------------------------------------------------------

That typicaly means you've not at any point in the schema reference chain imported the schema pertinent to the namespace referred for the prefix SOAP-ENV which of course you most probably mean to be for the root of the soap request itself.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic