title: Fatal Error - Content is not allowed in prolog
body: <p><a href="https://stackoverflow.com/questions/3395560/content-is-not-allowed-in-prolog">Similar to this question, but unfortunately didn't help</a></p>
  
  <p>I am trying to parse a String to XML in Java and keep getting the error:</p>
  
  <pre><code>[Fatal Error] output.txt:1:1: Content is not allowed in prolog.
  </code></pre>
  
  <p>I know it must be something to do with my XML string, because I ran a test with very basic XML and the error dissappeared.</p>
  
  <p><strong>XML</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xfa generator="ff99v250_01" APIVersion="1.4.3139.0"?&gt;
  &lt;jfxpf:XPF xmlns:jfxpf="http://www.xfa.com/schema/xml-package"&gt;
     &lt;jfxpf:Package&gt;
        &lt;jfxpf:Resource Location="GenReq"&gt;
           &lt;jfxpf:Link ContentType="application/x-jetform-cft" /&gt;
        &lt;/jfxpf:Resource&gt;
        &lt;jfxpf:Resource Location="default.xml"&gt;
           &lt;jfxpf:Content ContentType="text/xml" Location="default.xml"&gt;
              &lt;xfa:Data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/"&gt;
                 &lt;xfa:DataGroup&gt;
                    &lt;data xmlns:xfe="http://www.xfa.org/schema/xfa-events/1.0" xfe:script="$config.proto.common.template.uri='GenReq'" xfe:event="$config:load"&gt;
                       &lt;?jetform ^Dat ^page 1?&gt;
                       &lt;FR_NAME&gt;Administrator&lt;/FR_NAME&gt;
                       &lt;JFWF_DELEGATE /&gt;
                       &lt;ADHOC_DLN_ACTOR /&gt;
                       &lt;ADHOC_DLN_MSG /&gt;
                           &lt;ADHOC_DLN_TIME /&gt;
                       &lt;ADHOC_DLN_UNITS&gt;Days&lt;/ADHOC_DLN_UNITS&gt;
                       &lt;ADHOC_RMD_MSG /&gt;
                       &lt;ADHOC_RMD_TIME /&gt;
                       &lt;ADHOC_RMD_UNITS&gt;Days&lt;/ADHOC_RMD_UNITS&gt;
                       &lt;ADHOC_RPT_TIME /&gt;
                       &lt;ADHOC_RPT_UNITS&gt;Days&lt;/ADHOC_RPT_UNITS&gt;
                       &lt;CIRCULATETO /&gt;
                       &lt;COMPLETION /&gt;
                       &lt;FOLLOWUP /&gt;
                       &lt;MSGSUBJECT /&gt;
                       &lt;OTHERFIELD /&gt;
                       &lt;PRIORITY&gt;Low&lt;/PRIORITY&gt;
                       &lt;REQUEST /&gt;
                       &lt;RESPONSE /&gt;
                       &lt;Submit /&gt;
                       &lt;ADHOC_VALIDDATA&gt;True&lt;/ADHOC_VALIDDATA&gt;
                       &lt;JFWF_TRANID&gt;2xxyg9sffane7pwd5j8yv9t49s.1&lt;/JFWF_TRANID&gt;
                       &lt;JFWF_INSTRUCTION&gt;Initiate a General Request. Fill the request form, then identify the next participant.&lt;/JFWF_INSTRUCTION&gt;
                       &lt;JFWF_TRANSPORT&gt;HTTP&lt;/JFWF_TRANSPORT&gt;
                       &lt;JFWF_STATUS&gt;RECEIVED&lt;/JFWF_STATUS&gt;
                       &lt;JFWF_ACTION /&gt;
                       &lt;JFWF_CHOICE&gt;*Select Next Participant,Cancel&lt;/JFWF_CHOICE&gt;
                       &lt;JFWF_VERSION&gt;6.2&lt;/JFWF_VERSION&gt;
                       &lt;JFWF_READONLY&gt;1&lt;/JFWF_READONLY&gt;
                    &lt;/data&gt;
                 &lt;/xfa:DataGroup&gt;
              &lt;/xfa:Data&gt;
           &lt;/jfxpf:Content&gt;
        &lt;/jfxpf:Resource&gt;
     &lt;/jfxpf:Package&gt;
  &lt;/jfxpf:XPF&gt;
  </code></pre>
  
  <p>However, I am having trouble finding the text that is causing this issue. My Java code is below:</p>
  
  <pre><code>Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                      .parse(new InputSource(new StringReader(xml)));
  </code></pre>
  
  <p><strong>EDIT</strong>
  Removing the <code>Data</code> node works, so the error is somewhere deep in the XML. This does not throw an error:</p>
  
  <pre><code>&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;
  &lt;?xfa generator=\"ff99v250_01\" APIVersion=\"1.4.3139.0\"?&gt;
  &lt;jfxpf:XPF xmlns:jfxpf=\"http://www.xfa.com/schema/xml-package\"&gt;
      &lt;jfxpf:Package&gt;
          &lt;jfxpf:Resource Location=\"GenReq\"&gt;
              &lt;jfxpf:Link ContentType=\"application/x-jetform-cft\"/&gt;
          &lt;/jfxpf:Resource&gt;
          &lt;jfxpf:Resource Location=\"default.xml\"&gt;
              &lt;jfxpf:Content ContentType=\"text/xml\" Location=\"default.xml\"&gt;
              &lt;/jfxpf:Content&gt;
          &lt;/jfxpf:Resource&gt;
      &lt;/jfxpf:Package&gt;
   &lt;/jfxpf:XPF&gt;
  </code></pre>
  
  <p><strong>My Imports</strong></p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.io.StringReader;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import javax.swing.JFileChooser;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import org.w3c.dom.Document;
  import org.w3c.dom.NodeList;
  import org.xml.sax.InputSource;
  </code></pre>