I am using a toolkit called 'beanio' to parse a fixed length flat file in Java. With the toolkit I am required to define the file format with an XML document. I can refer to the schema location on the beanio website, but i'd much rather use a local copy. The reason is that I want to be sure that in case anything happens to the site, I will have a working program.
My problem is that when I try to reference the xsd file locally, the SAX engine throws an error about malformed xml / definitions. The following will work:
<beanio xmlns="http://www.beanio.org/2012/03"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 http://www.beanio.org/2012/03/mapping.xsd">
However, the following will not:
<!DOCTYPE beanio SYSTEM "resources/formatting/mapping.xsd">
<beanio>
These files, mapping.xsd, whether referenced locally or on the internet are exactly the same.
The error thrown is as follows:
Caused by: org.xml.sax.SAXParseException; systemId: file:///C:/workspace/LookupsFileProcessor/resources/formatting/mapping.xsd; lineNumber: 2; columnNumber: 2; The markup declarations contained or pointed to by the document type declaration must be well-formed.
This has been extremely frustrating. The toolkits for flat file parsing for java are very old and out dated. I have tried FOUR of them and some either don't have a usable API or they rely on external DTD/XSD definitions which cause me to run into this same exact issue.
I understand XML well enough, or so I thought, and I am not sure what is the issue here.
Well boy do I feel ridiculous. So the method of formatting using a DTD is specified using a doctype declaration. In my example I am actually using XSD to do my XML formatting which is a different technology than DTD.
The correct way to specify a local XSD file using the XML Schema method is simply as follows:
<beanio xmlns="http://www.beanio.org/2012/03" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.beanio.org/2012/03 resources/formatting/mapping.xsd">
I hope I can help anyone else from looking foolish. Thanks!