<p>I'm trying to find a way to validate a large XML file against an XSD. I saw the question <a href="https://stackoverflow.com/questions/15732/whats-the-best-way-to-validate-an-xml-file-against-an-xsd-file">...best way to validate an XML...</a> but the answers all pointed to using the Xerces library for validation. The only problem is, when I use that library to validate a 180 MB file then I get an OutOfMemoryException.</p>

<p>Are there any other tools,libraries, strategies for validating a larger than normal XML file?</p>

<p>EDIT: The SAX solution worked for java validation, but the other two suggestions for the libxml tool were very helpful as well for validation  outside of java.</p>

[{'answer_id': 40678, 'author': 'jodonnell', 'author_id': 4223, 'author_profile': 'https://Stackoverflow.com/users/4223', 'pm_score': 6, 'selected': True, 'text': '<p>Instead of using a DOMParser, use a SAXParser.  This reads from an input stream or reader so you can keep the XML on disk instead of loading it all into memory.</p>\n\n<pre><code>SAXParserFactory factory = SAXParserFactory.newInstance();\nfactory.setValidating(true);\nfactory.setNamespaceAware(true);\n\nSAXParser parser = factory.newSAXParser();\n\nXMLReader reader = parser.getXMLReader();\nreader.setErrorHandler(new SimpleErrorHandler());\nreader.parse(new InputSource(new FileReader ("document.xml")));\n</code></pre>\n'}, {'answer_id': 40681, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 3, 'selected': False, 'text': '<p>Use <a href="http://xmlsoft.org/" rel="noreferrer">libxml</a>, which performs validation <em>and</em> has a streaming mode.</p>\n'}, {'answer_id': 40956, 'author': 'dlamblin', 'author_id': 459, 'author_profile': 'https://Stackoverflow.com/users/459', 'pm_score': 2, 'selected': False, 'text': '<p>Personally I like to use <a href="http://xmlstar.sourceforge.net/" rel="nofollow noreferrer">XMLStarlet</a> which has a command line interface, and works on streams. It is a set of tools built on Libxml2.</p>\n'}, {'answer_id': 628133, 'author': 'GaZ', 'author_id': 62667, 'author_profile': 'https://Stackoverflow.com/users/62667', 'pm_score': 1, 'selected': False, 'text': '<p>SAX and libXML will help, as already mentioned. You could also try increasing the maximum heap size for the JVM using the -Xmx option. E.g. to set the maximum heap size to 512MB: <code>java -Xmx512m com.foo.MyClass</code></p>\n'}]
['https://Stackoverflow.com/questions/40663', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3274/']