Link to home
Start Free TrialLog in
Avatar of srikotesh
srikotesh

asked on

how to validate xml files using java

Hi Experts,
how to validate xml using java
i dont want any data from the xml just need validate it as valid xml or not
Avatar of girionis
girionis
Flag of Greece image

It depends on what kind of parser you're using (SAX/DOM).

Java has built-in support for validation. For sample code have a look at the validation package:

https://docs.oracle.com/javase/7/docs/api/javax/xml/validation/package-summary.html
Valid XML or valid against his XSD?
Avatar of srikotesh
srikotesh

ASKER

hi Theo,

valid xml only.

hi girionis,
from that link I am not sure what is the myxsd  I have to pass.

Source schemaFile = new StreamSource(new File("mySchema.xsd"));

Domparser I am using to validate xml
Are you using a DocumentBuilderFactory? If yes then you simply need to do:

factory.setValidating(true);
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.