Unexpected EOF in prolog when parsing XML
<p>I have this XML Document which is the body of a SOAP request:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;mes:SubmitStructureRequest xmlns:mes="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/message" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:com="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/common" xmlns:str="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/structure" xmlns:reg="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/registry" xmlns:web="http://www.sdmx.org/resources/sdmxml/schemas/v2_1/webservices"&gt;
            &lt;mes:Header&gt;
               &lt;mes:ID&gt;TEST_DFD&lt;/mes:ID&gt;
               &lt;mes:Test&gt;true&lt;/mes:Test&gt;
               &lt;mes:Prepared&gt;2013-10-10&lt;/mes:Prepared&gt;
               &lt;mes:Sender id="TESTER"/&gt;
               &lt;mes:Receiver id="ESTAT"/&gt;
            &lt;/mes:Header&gt;
            &lt;mes:SubmitStructureRequest action="Append"&gt;
               &lt;str:Structures&gt;
                  &lt;str:Dataflows&gt;
                     &lt;str:Dataflow agencyID="ESTAT" id="DFD_TEST_21" version="1.0"&gt;
                        &lt;com:Name xml:lang="en"&gt;Production in construction, total, building construction, civil engineering (Monthly)&lt;/com:Name&gt;
                        &lt;str:Structure&gt;
                           &lt;Ref agencyID="ESTAT" class="DataStructure" id="STS" package="datastructure" version="2.0"/&gt;
                        &lt;/str:Structure&gt;
                     &lt;/str:Dataflow&gt;
                  &lt;/str:Dataflows&gt;
               &lt;/str:Structures&gt;
            &lt;/mes:SubmitStructureRequest&gt;
&lt;/mes:SubmitStructureRequest&gt;
</code></pre>

<p>I'm trying to parse it using this piece of Java code (The stream is the aforementioned xml):</p>

<pre><code>InputStream stream = sourceData.getInputStream();
        try {
            XMLInputFactory factory = XMLInputFactory.newInstance();
            XMLStreamReader parser = factory.createXMLStreamReader(stream);
            while (parser.hasNext()) {
                int event = parser.next();
                if (event == XMLStreamConstants.START_ELEMENT) {
                    for(int i = 0 ; i &lt; parser.getNamespaceCount(); i ++) {
                        String ns = parser.getNamespaceURI(i);
                        if(SdmxConstants.getNamespacesV1().contains(ns)) {
                            return SDMX_SCHEMA.VERSION_ONE;
                        }
                        if(SdmxConstants.getNamespacesV2().contains(ns)) {
                            return SDMX_SCHEMA.VERSION_TWO;
                        }
                        if(SdmxConstants.getNamespacesV2_1().contains(ns)) {
                            return SDMX_SCHEMA.VERSION_TWO_POINT_ONE;
                        }
                    }
                    throw new SdmxSyntaxException("Can not get Scheme Version from SDMX message.  Unable to determine structure type from Namespaces- please ensure this is a valid SDMX document");
                }
            }
            throw new SdmxSyntaxException(ExceptionCode.XML_PARSE_EXCEPTION, "No root node found");
        } catch(XMLStreamException e) {
            throw new SdmxSyntaxException(ExceptionCode.XML_PARSE_EXCEPTION, e);
        } finally {
            if(stream != null) {
                try {
                    stream.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }
</code></pre>

<p>At the point of <code>int event = parser.next();</code> I get:</p>

<blockquote>
  <p>com.ctc.wstx.exc.WstxEOFException: Unexpected EOF in prolog</p>
</blockquote>

<p>Any ideas why is this happening?</p>