S
Samuel Penn
I'm trying to validate an XML document against a Schema, but keep on
running up against an error along the lines of:
Error: URI=null Line=3: Element type "article" is not declared.
Error: URI=null Line=4: Attribute "xmlns:xsi" is not declared for element
"article".
Error: URI=null Line=4: Attribute "xsi:noNamespaceSchemaLocation" is not
declared for element "article".
Error: URI=null Line=5: Element type "body" is not declared.
The code I am using is as follows:
private void
load(InputSource in) {
try {
DocumentBuilderFactory dbf;
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
document = db.parse(in);
} catch (Exception e) {
e.printStackTrace();
}
}
If validation isn't switched on, then the document loads fine. The
document also validates against an online validator I've found.
(http://tools.decisionsoft.com/schemaValidate.html).
I also get a similar error if I try to validate using the xmlvalidate
task in Ant 1.6. I'm guessing that it's not loading the schema, even
though the schema is declared in the XML document.
xmllint also worked with these documents, though doesn't seem to support
substitutionGroup (at least, not the version I have).
If anyone has any ideas, I'd be grateful. XML and XSD are attached.
running up against an error along the lines of:
Error: URI=null Line=3: Element type "article" is not declared.
Error: URI=null Line=4: Attribute "xmlns:xsi" is not declared for element
"article".
Error: URI=null Line=4: Attribute "xsi:noNamespaceSchemaLocation" is not
declared for element "article".
Error: URI=null Line=5: Element type "body" is not declared.
The code I am using is as follows:
private void
load(InputSource in) {
try {
DocumentBuilderFactory dbf;
dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating(true);
DocumentBuilder db = dbf.newDocumentBuilder();
document = db.parse(in);
} catch (Exception e) {
e.printStackTrace();
}
}
If validation isn't switched on, then the document loads fine. The
document also validates against an online validator I've found.
(http://tools.decisionsoft.com/schemaValidate.html).
I also get a similar error if I try to validate using the xmlvalidate
task in Ant 1.6. I'm guessing that it's not loading the schema, even
though the schema is declared in the XML document.
xmllint also worked with these documents, though doesn't seem to support
substitutionGroup (at least, not the version I have).
If anyone has any ideas, I'd be grateful. XML and XSD are attached.