title: Parse XML into DOM tree with custom object implementations in Java
body: <p>I want to parse an XML document into a DOM tree in Java such that certain objects (e.g. instances of <code>org.w3c.dom.Node</code> or <code>org.w3c.dom.Element</code>) in the tree can be downcast to instances of classes that I have created, while minimizing the amount of XML-related code that I need to (re)implement. As a (very simple) example, if I have an XML element like:</p>
  
  <pre><code>&lt;Vector size="5"&gt;
    1.0 -1.0 3.0 -2.73e2
  &lt;/Vector&gt;
  </code></pre>
  
  <p>I would like to customize the parser to instantiate the following for it:</p>
  
  <pre><code>public class Vector extends /* some parser class */ {
    private double[] elements;
  
    /* constructors; etc.*/
  
    public double dotProduct(Vector v) {
      /* implementation */
    }
  }
  </code></pre>
  
  <p>such that I can pass instances of <code>Vector</code> created by the parser to, for example, <code>javax.xml.xpath</code> objects' methods and have them work correctly. What is the quickest way to achieve this? Is it possible with Java SE alone, or are third-party libraries (e.g. Xerces) necessary?</p>