Validating xml file against xsd

Rated 3.96/5 based on 612 customer reviews

Added to the end of my filename, and the validation started to work.

W3C_XML_SCHEMA_NS_URI); // load a WXS schema, represented by a Schema instance Source schema File = new Stream Source(new File("my Schema.xsd")); Schema schema = Schema(schema File); // create a Validator instance, which can be used to validate an instance document Validator validator = Validator(); // validate the DOM tree try catch (SAXException e) It validates against dtd and xsd. In debian squeeze it is located in the package "libxerces-c-samples". The other answers work here as well, because the files "map" to the namespaces declared in the file, because they declare a namespace, and if matches up with the namespace in the file, you're good. This will start creating DOM objects as it parses the document - wasteful if you aren't going to use them.The definition of the dtd and xsd has to be in the xml! One more answer: since you said you need to validate files you are generating (writing), you might want to validate content while you are writing, instead of first writing, then reading back for validation.You can probably do that with JDK API for Xml validation, if you use SAX-based writer: if so, just link in validator by calling 'Validator.validate(source, result)', where source comes from your writer, and result is where output needs to go.

Leave a Reply