In the scope of different projects I often have to validate XML files. Here is my solution to verify XML files using a schema.
First of all to validate XML files in Java you need create a
SchemaFactory of the W3C XML schema language and you have to compile the schema (let’s assume it’s located in
Now you’re able to create a validator from the schema.
In order to validate a XML file you have to read it (let’s assume it’s located in
Last but not least you can validate the file: