0

Suppose I have an XML schema .xsd file which has many such <xsd:include schemaLocation="../Common/{dir}" /> elements among other types of xsd:include statements. I am trying to validate an input file in java:

public static void validate(String xml_file, String schema_file, String base_dir) throws 
 SAXException, IOException {
     SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
     InputStream input_stream = new FileInputStream(schema_file);
     ((sf.newSchema(new StreamSource(input_stream, base_dir))).newValidator()).validate(new StreamSource(new File(xml_file)));
 }

However, I am getting a Cannot find the declaration of element '[element_type]', when that [element_type] is clearly referred to in the schema_file include statements. Is there something I am doing wrong? How can I go about fixing this?

user100123122
  • 309
  • 4
  • 11
  • My suspicions would fall on the value of `base_dir`. – Michael Kay Mar 06 '21 at 08:37
  • Does this answer your question? [How to validate an XML file using Java with an XSD having an include?](https://stackoverflow.com/questions/2342808/how-to-validate-an-xml-file-using-java-with-an-xsd-having-an-include) – Progman Mar 06 '21 at 09:57
  • For `base_dir` I am providing the path to the deepest folder containing my `schema_file`. I am not sure what value to pass. – user100123122 Mar 06 '21 at 15:56

0 Answers0