title: Throwing SAXException
body: <p>Learning xml parsing with Java, and am working in a test program to try things out as I go. All of the test System.out.println()'s were what I expected in the console except childElement was returning [name: null] and childElement.getNodeValue() was returning null rather than [name: "Branch Name"] and "Branch Name" respectively. </p>
  
  <p>In an effort to correct that I started tweaking and of course broke the program further. Now, I'm throwing a SAXException (I've marked the line that I've narrowed it down to with a comment, although I'm not exactly clear on what a SAXException means, etc) when I try to run and I can't seem to get her back to where she was before.</p>
  
  <p>Here's where the codes at now:</p>
  
  <pre><code>package uploaders;
  
  import javax.swing.*;
  import javax.xml.parsers.*;
  import org.w3c.dom.*;
  import org.xml.sax.SAXException;
  import java.awt.EventQueue;
  import java.io.*;
  
  public class Test {
      public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException { 
          JFileChooser chooser = new JFileChooser();
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();
          StringBuilder xmlStringBuilder = new StringBuilder();
          String appendage = "&lt;?xml version=\"1.0\"?&gt;&lt;branch0&gt;&lt;name&gt;Branch Name&lt;/name&gt;&lt;/branch0&gt;";
          ByteArrayInputStream input = new ByteArrayInputStream(xmlStringBuilder.toString().getBytes("UTF-8"));
  
          chooser.setCurrentDirectory(new File("."));
          chooser.setMultiSelectionEnabled(false);
          chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
  
          int result = chooser.showOpenDialog(null);
  
          if (result == JFileChooser.APPROVE_OPTION) { 
              System.out.println("Test Results:");
              System.out.println();
              System.out.println(chooser.getSelectedFile().getPath()); 
  
              Document doc = builder.parse(input); //originally org.w3c.dom.Document...this line is where SAXException is thrown.
              Element root = doc.getDocumentElement(); 
              NodeList children = root.getChildNodes();
  
              System.out.println(root.getTagName());
              xmlStringBuilder.append(appendage); //forgot to move this up too (thanks @Vihar)
  
              for (int i = 0; i &lt; children.getLength(); i++) {
                  Node child = children.item(i);
                  if (child instanceof Element) { 
                      Element childElement = (Element) child; 
                      System.out.println(childElement.getTagName());
                      System.out.println(childElement.getNodeValue());
                      System.out.println(childElement); }
              }
          }   
      }
  }
  </code></pre>
  
  <p>Any help with the SAXException is much appreciated, and after that I'll still probably need to figure out why the "name" element returns "null", but first things first :).</p>
  
  <p><strong><em>Updated</em></strong>
  Shown in comments what was causing the SAXException. Console is still displaying this however:</p>
  
  <pre><code>Test Results:
  
  /Users/.../Documents/java/Test/./bin
  branch0
  name
  null           //I'm expecting "Branch Name"
  [name: null]   //and "[name: Branch Name]"
  </code></pre>
  
  <p><strong><em>Finally</em></strong></p>
  
  <pre><code>childElement.getNodeValue() //needed + .toString() to work or:
  childElement.getNodeValue().toString()
  </code></pre>
  
  <p>or</p>
  
  <pre><code>childElement.getTextContent()
  </code></pre>