nisha
nisha

Reputation: 711

XML validation using Java Code

I have set of XML files and they have a particular stucture. I want to validate the XML so that the stucture is fine always before using it.

Can anyone help with some samples like how to validate the XML files using java code.

Thanks...

Upvotes: 2

Views: 205

Answers (1)

Adrian Smith
Adrian Smith

Reputation: 17553

You need to create an XML Schema file (.xsd). This will define which elements may and may not be present in the file.

You can then use Java libraries to check that the XML file you have is compatible against this schema, see here: http://java.sun.com/developer/technicalArticles/xml/validationxpath/

Upvotes: 2

Related Questions