How to consume XML with Java?

Could have been easier, no?

I have this nice sample xml file, which is called library.xml...
        <book id="bk101">
            <author>Gambardella, Matthew</author>
            <title>XML Developer's Guide</title>
            <description>Nice book!</description>
        <book id="bk102">
            <author>Ralls, Kim</author>
            <title>Midnight Rain</title>
            <description>Some description here.</description>
        <book id="bk103">
            <author>Corets, Eva</author>
            <title>Maeve Ascendant</title>
            <description>Best book ever!</description>

Here is the Java code:
package biz.tugay.deleteNow;
/* User: Date: 19/12/15 Time: 18:12 */
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
public class OtherTestClass {
    public static void main(String[] args) throws Exception {
        Document doc = getDocument();
        String xpath = "/library/catalog/book[2]/author";
        extractInfo(xpath, doc);
        xpath = "/library/catalog/book[2]/title";
        extractInfo(xpath, doc);
    private static Document getDocument() throws Exception {
        DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
        // Parse the XML file and build the Document:
        Document doc = docBuilder.parse(new File("/Users/koraytugay/Desktop/library.xml"));
        return doc;
    private static void extractInfo(String xpath, Document doc) throws Exception {
        System.out.print("Result for xpath: " + xpath + ": ");
        // Catches the first node that meets the criteria of xpath string
        XObject eval = XPathAPI.eval(doc, xpath);
    private static void getRootNodeAndPrint(Document doc) {
        Node root = doc.getDocumentElement();
        System.out.print("Root element of the doc is: " + root.getNodeName() + ".");

And finally the output:
Result for xpath: /library/catalog/book[2]/author: Ralls, Kim
Result for xpath: /library/catalog/book[2]/title: Midnight Rain
Root element of the doc is: library.