• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Xml validation against xsd in DOM

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ruth Stout was famous for gardening naked. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic