XML Schema validation
I am having some problems validating XML against a schema. I have an XML document and a very simple schema file, when I run it against the code below it fails. However, when I manually add my schema definition to my XML file and run "Validate XML" in Netbeans it passes. The validation is complaining about the root node not being defined. This is the same error you get in Netbeans when you don't define a schema. Is there something else I have to do to make validate use my schema file? I don't want to define the schema definition in the XML file because I am validating XML files that I have no control over.
The exact error I get is:
Error validating XML against schemacvc-elt.1: Cannot find the declaration of element rootNode
where rootNode is the rootNode of my document. I even changed my schema file to not have any constraints and it still complains with the same error.
File schema = new File(xsdLocation);
Document xmlDoc = getXMLDocument(xmlFile);
SchemaFactory factory =
Schema schema = factory.newSchema(schemaFile);
Validator validator = schema.newValidator();
DOMSource dom = new DOMSource(xmlDoc);
Solved this one. Had a namespace issue. Just changed my XSD to only have this at the top: