title: Java - Reading XML file
body: <p>I am trying to read in some data from an XML file and having some trouble, the XML I have is as follows:</p>
  
  <pre><code>&lt;xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;EmailSettings&gt;
      &lt;recipient&gt;test@test.com&lt;/recipient&gt;
      &lt;sender&gt;test2@test.com&lt;/sender&gt;
      &lt;subject&gt;Sales Query&lt;/subject&gt;
      &lt;description&gt;email body message&lt;/description&gt;
  &lt;/EmailSettings&gt;
  </code></pre>
  
  <p>I am trying to read these values as strings into my Java program, I have written this code so far:</p>
  
  <pre><code>private static Document getDocument (String filename){
      try {
  
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  
          factory.setIgnoringComments(true);
          factory.setIgnoringElementContentWhitespace(true);
          factory.setValidating(false);
  
          DocumentBuilder builder = factory.newDocumentBuilder();
          return builder.parse(new InputSource(filename));        
      }
      catch (Exception e){
          System.out.println("Error reading configuration file:");
          System.out.println(e.getMessage());
      }
      return null;
  }
  
  Document doc = getDocument(configFileName);
  
  Element config = doc.getDocumentElement();
  </code></pre>
  
  <p>I am struggling with reading in the actual string values though.</p>