you can use XML parsers to validate your xml instance document against either DTD or Schema.
xerces is best example of such parser. Try running sax.Counter which will validate your xml document.
you might have to download xerces jar package from
www.apache.com. java sax.Counter example.xml