<p>What is the best method to parse multiple, discrete, custom XML documents with Java?</p>

[{'answer_id': 23121, 'author': 'jcsalterego', 'author_id': 1416, 'author_profile': 'https://Stackoverflow.com/users/1416', 'pm_score': 2, 'selected': False, 'text': '<p>You will want to use <code>org.xml.sax.XMLReader</code> (<a href="http://docs.oracle.com/javase/7/docs/api/org/xml/sax/XMLReader.html" rel="nofollow noreferrer">http://docs.oracle.com/javase/7/docs/api/org/xml/sax/XMLReader.html</a>).</p>\n'}, {'answer_id': 23300, 'author': 'dlinsin', 'author_id': 198, 'author_profile': 'https://Stackoverflow.com/users/198', 'pm_score': 4, 'selected': True, 'text': '<p>I would use <a href="http://jcp.org/en/jsr/detail?id=173" rel="noreferrer">Stax</a> to parse XML, it\'s fast and easy to use. I\'ve been using it on my last project to parse XML files up to 24MB. There\'s a nice introduction on <a href="http://today.java.net/pub/a/today/2006/07/20/introduction-to-stax.html" rel="noreferrer">java.net</a>, which tells you everything you need to know to get started.</p>\n'}, {'answer_id': 4377373, 'author': 'Valentin Rocher', 'author_id': 104117, 'author_profile': 'https://Stackoverflow.com/users/104117', 'pm_score': 2, 'selected': False, 'text': '<p>Basically, you have two main XML parsing methods in Java :</p>\n\n<ul>\n<li><a href="http://en.wikipedia.org/wiki/Simple_API_for_XML" rel="nofollow">SAX</a>, where you use an <a href="http://download.oracle.com/javase/6/docs/api/org/xml/sax/helpers/DefaultHandler.html" rel="nofollow">handler</a> to only grab what you want in your XML and ditch the rest</li>\n<li><a href="http://en.wikipedia.org/wiki/Document_Object_Model" rel="nofollow">DOM</a>, which parses your file all along, and allows you to grab all elements in a more tree-like fashion.</li>\n</ul>\n\n<p>Another very useful XML parsing method, albeit a little more recent than these ones, and included in the JRE only since Java6, is <a href="http://en.wikipedia.org/wiki/StAX" rel="nofollow">StAX</a>. StAX was conceived as a medial method between the tree-based of DOM and event-based approach of SAX. It is quite similar to SAX in the fact that parsing very large documents is easy, but in this case the application "pulls" info from the parser, instead of the parsing "pushing" events to the application. You can find more explanation on this subject <a href="http://www.xml.com/pub/a/2003/09/17/stax.html" rel="nofollow">here</a>.</p>\n\n<p>So, depending on what you want to achieve, you can use one of these approaches.</p>\n'}, {'answer_id': 5299126, 'author': 'Noam Nevo', 'author_id': 458576, 'author_profile': 'https://Stackoverflow.com/users/458576', 'pm_score': 2, 'selected': False, 'text': '<p>If you only need to parse then I would recommend using XPath library. Here is a nice reference: <a href="http://www.ibm.com/developerworks/library/x-javaxpathapi.html" rel="nofollow">http://www.ibm.com/developerworks/library/x-javaxpathapi.html</a></p>\n\n<p>But you may want to consider turning XMLs to objects and then the sky is the limit. \nFor that you may use <a href="http://xstream.codehaus.org/" rel="nofollow">XStream</a>, this is a great library which i use alot</p>\n'}, {'answer_id': 5299265, 'author': 'Valdis', 'author_id': 438990, 'author_profile': 'https://Stackoverflow.com/users/438990', 'pm_score': 2, 'selected': False, 'text': '<p>Use the <a href="http://dom4j.sourceforge.net/dom4j-1.6.1/guide.html" rel="nofollow">dom4j</a> library</p>\n\n<p>First read the document</p>\n\n<pre><code>import java.net.URL;\n\nimport org.dom4j.Document;\nimport org.dom4j.DocumentException;\nimport org.dom4j.io.SAXReader;\n\npublic class Foo {\n\n    public Document parse(URL url) throws DocumentException {\n        SAXReader reader = new SAXReader();\n        Document document = reader.read(url);\n        return document;\n    }\n}\n</code></pre>\n\n<p>Then use XPATH to get to the values you need</p>\n\n<pre><code>public void get_author(Document document) {\n    Node node = document.selectSingleNode( "//AppealRequestProcessRequest/author" );\n    String author = node.getText();\n    return author;\n}\n</code></pre>\n'}, {'answer_id': 36190454, 'author': 'vtd-xml-author', 'author_id': 129732, 'author_profile': 'https://Stackoverflow.com/users/129732', 'pm_score': 0, 'selected': False, 'text': '<p>Below is the code of extracting some value value using <a href="http://vtd-xml.sf.net" rel="nofollow">vtd-xml</a>.</p>\n\n<pre><code>import com.ximpleware.*;\n\npublic class extractValue{\n    public static void  main(String s[]) throws VTDException, IOException{\n        VTDGen vg = new VTDGen();\n        if (!vg.parseFile("input.xml", false));\n        VTDNav vn = vg.getNav();\n        AutoPilot ap = new AutoPilot(vn);\n        ap.selectXPath("/aa/bb[name=\'k1\']/value");\n        int i=0;\n        while ((i=ap.evalXPath())!=-1){\n            System.out.println(" value ===&gt;"+vn.toString(i));\n        }   \n    }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/23106', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/828/']