Similar to this question, but unfortunately didn't help
I am trying to parse a String to XML in Java and keep getting the error:
[Fatal Error] output.txt:1:1: Content is not allowed in prolog.
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.
XML
<?xml version="1.0" encoding="UTF-8"?>
<?xfa generator="ff99v250_01" APIVersion="1.4.3139.0"?>
<jfxpf:XPF xmlns:jfxpf="http://www.xfa.com/schema/xml-package">
<jfxpf:Package>
<jfxpf:Resource Location="GenReq">
<jfxpf:Link ContentType="application/x-jetform-cft" />
</jfxpf:Resource>
<jfxpf:Resource Location="default.xml">
<jfxpf:Content ContentType="text/xml" Location="default.xml">
<xfa:Data xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/">
<xfa:DataGroup>
<data xmlns:xfe="http://www.xfa.org/schema/xfa-events/1.0" xfe:script="$config.proto.common.template.uri='GenReq'" xfe:event="$config:load">
<?jetform ^Dat ^page 1?>
<FR_NAME>Administrator</FR_NAME>
<JFWF_DELEGATE />
<ADHOC_DLN_ACTOR />
<ADHOC_DLN_MSG />
<ADHOC_DLN_TIME />
<ADHOC_DLN_UNITS>Days</ADHOC_DLN_UNITS>
<ADHOC_RMD_MSG />
<ADHOC_RMD_TIME />
<ADHOC_RMD_UNITS>Days</ADHOC_RMD_UNITS>
<ADHOC_RPT_TIME />
<ADHOC_RPT_UNITS>Days</ADHOC_RPT_UNITS>
<CIRCULATETO />
<COMPLETION />
<FOLLOWUP />
<MSGSUBJECT />
<OTHERFIELD />
<PRIORITY>Low</PRIORITY>
<REQUEST />
<RESPONSE />
<Submit />
<ADHOC_VALIDDATA>True</ADHOC_VALIDDATA>
<JFWF_TRANID>2xxyg9sffane7pwd5j8yv9t49s.1</JFWF_TRANID>
<JFWF_INSTRUCTION>Initiate a General Request. Fill the request form, then identify the next participant.</JFWF_INSTRUCTION>
<JFWF_TRANSPORT>HTTP</JFWF_TRANSPORT>
<JFWF_STATUS>RECEIVED</JFWF_STATUS>
<JFWF_ACTION />
<JFWF_CHOICE>*Select Next Participant,Cancel</JFWF_CHOICE>
<JFWF_VERSION>6.2</JFWF_VERSION>
<JFWF_READONLY>1</JFWF_READONLY>
</data>
</xfa:DataGroup>
</xfa:Data>
</jfxpf:Content>
</jfxpf:Resource>
</jfxpf:Package>
</jfxpf:XPF>
However, I am having trouble finding the text that is causing this issue. My Java code is below:
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new InputSource(new StringReader(xml)));
EDIT
Removing the Data
node works, so the error is somewhere deep in the XML. This does not throw an error:
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<?xfa generator=\"ff99v250_01\" APIVersion=\"1.4.3139.0\"?>
<jfxpf:XPF xmlns:jfxpf=\"http://www.xfa.com/schema/xml-package\">
<jfxpf:Package>
<jfxpf:Resource Location=\"GenReq\">
<jfxpf:Link ContentType=\"application/x-jetform-cft\"/>
</jfxpf:Resource>
<jfxpf:Resource Location=\"default.xml\">
<jfxpf:Content ContentType=\"text/xml\" Location=\"default.xml\">
</jfxpf:Content>
</jfxpf:Resource>
</jfxpf:Package>
</jfxpf:XPF>
My Imports
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;