Java API for XML validation of a document
XML Schema defines how an instance of an XML document should look like.
Most of the XML documents that are created are usually validated against
a particular schema so that the XML document conforms to the standards
needed before it is processed.
ensures that the XML document does not contain any irrelevant element
that might hinder the processing of the XML document.
javax.xml.validation contains all the classes needed for validating an
XML document against a schema. The other imports that might be needed
to validate an XML document are given below.
Now the first
step is to create a new document object and load the XML file into it.
For this you will be using DocumentBuilderFactory and the DocumentBuilder
objects. Create an instance of a SchemaFactory object.
a StreamSource for loading the Schema file into it. Now the next step
is to create a Schema object and use the SchemaFactory's newSchema() method
to load the schema into it.
Now for doing
the validation you have to create a Validator object and link that to
the Schema. Now use the validate() method of the validator object and
load the XML source for validation against the particular schema.
for using the above methods are available in plenty in the internet.
Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.
: We never rent, trade, or sell my email lists to
We assure that your privacy is respected