0

I have an xml and an xsd file. Inside the xml file I have given the xsd name.

xsi:schemaLocation="http://www.orc.com/mrb/schemas Invoice.xsd">

When I am parsing the xml using SAX parser I am getting the following error >

> XML-20149: (Error) Element 'InvList' used but not declared.

Isn't it enough to mention the xsd file in xml enough to find the definitions.

Following is the code

InputSource source = null;
String inputFile = null;
File xmlFile = null;
InputStream is = null;


 SAXParser saxParser = null;
 SAXParserFactory sPF = SAXParserFactory.newInstance();
 sPF.setFeature("http://xml.org/sax/features/validation", true);
 sPF.setNamespaceAware(true);
 sPF.setXIncludeAware(false);
 saxParser = sPF.newSAXParser();


try {
    SAXParser saxParser = MyUtils.getSAXParser();
    XMLReader parser = saxParser.getXMLReader();
    parser.setContentHandler(this);
    parser.setErrorHandler(this);
    inputFile = new String("InvoiceTmp.xml");

    xmlFile = new File(inputFile);
    is = new FileInputStream(xmlFile);
    source = new InputSource(is);
    parser.parse(source);
    
} catch (Exception e) {
    MyLog.log(ErrorLog.Error, "Error while parsing XML #1 \n" +  e.getMessage());
}
Chandu
  • 1,837
  • 7
  • 30
  • 51
  • Really you should post a [mcve] to get the best help. See [ask]. Short of that, check your targetNamespace declaration in the XSD and see duplicate link for a model to follow. – kjhughes Sep 30 '20 at 14:29
  • declarations are all fine. It was working with Apache xerces library. But failing with Java Standard implementation. – Chandu Oct 01 '20 at 06:21
  • The added Java code improves the question, but you've still not provide enough information for readers to reproduce your issue. There are no reduced XML and XSD files, for example. – kjhughes Oct 01 '20 at 12:26

0 Answers0