title: Java - XML read root element value
body: <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;JDF DescriptiveName="DescriptiveName" ID="n0001" JobID="1101-CCC-0" JobPartID="1" ProjectID=""&gt;
  &lt;Comment Name="Materialnummer"&gt;XXXXXXX&lt;/Comment&gt;
  &lt;NodeInfo LastEnd="2014-03-12T18:00:00+01:00"&gt;
  &lt;EmployeeRef rRef="EMPCSR"/&gt;
  &lt;/NodeInfo&gt;
  &lt;CustomerInfo CustomerID="1740"&gt;
  &lt;/CustomerInfo&gt;
  &lt;ResourcePool&gt;
  &lt;/ResourcePool&gt;
  &lt;ResourceLinkPool&gt;
  &lt;/ResourceLinkPool&gt;
  &lt;JDF Category="FinalImaging" ID="n0002" Status="Waiting" Type="ProcessGroup" Types="XXX"&gt;
  &lt;ResourcePool&gt;
  &lt;/ResourcePool&gt;
  &lt;ResourceLinkPool&gt;
  &lt;/ResourceLinkPool&gt;
  &lt;/JDF&gt;
  &lt;JDF ID="n0002" Status="Waiting" Type="ProcessGroup" Types="PrePressPreparation"&gt;
  &lt;ResourcePool&gt;
  &lt;/ResourcePool&gt;
  &lt;ResourceLinkPool&gt;
  &lt;/ResourceLinkPool&gt;
  &lt;/JDF&gt;
  &lt;/JDF&gt;
  </code></pre>
  
  <p>How do I get the root element value. For this example I want to get the <strong>DescriptiveName</strong>,<strong>ID</strong>,<strong>JobID</strong> and <strong>ProjectID</strong>. I managed to read other values but stuck in root emlement. Please advice.
  <strong>EDITED</strong></p>
  
  <pre><code>DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
                  DocumentBuilder builder = builderFactory.newDocumentBuilder();
                  Document xmlDocument = builder.parse(file);
                  XPath xPath = XPathFactory.newInstance().newXPath();
                  //System.out.println("*************************");
                  String expression = "/JDF";
                  NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
  </code></pre>