2

I am getting following exception while parsing XML

org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM][lL]" is not allowed.

SOAp Request i am sending:

<soap:Envelope>
   <soap:Header/>
   <soap:Body>
      <ver:ReceiveOnlineBatchExternalAttachment>
         <web:username>user</web:username>
         <web:passwd>pass</web:passwd>
         <web:receiversReference>1232323</web:receiversReference>
         <web:sequenceNumber>1</web:sequenceNumber>
         <web:batch>
            <![CDATA[
              <?xml version="1.0" encoding="UTF-8"?> 
              <DataBatch>
                <DataUnits>
                 <DataUnit>
                  <FormTask>
                   <ServiceCode>323015</ServiceCode>
                   <Form>
                    <FormData>
                            <![CDATA[<melding> </melding>]]
                    </FormData>
                   </Form>
                  </FormTask>
               </DataUnit>
             </DataUnits>
           </DataBatch>
         ]]>>
        </web:batch>
      </ver:ReceiveOnlineBatchExternalAttachment>
   </soap:Body>
</soap:Envelope>

I have done changes to CDATA multiple times but getting same error. Could anyone suggest how CDATA within CDATA can be handled in this request?

Tried following but failed:

         <![CDATA[ <elements> <![CDATA[<melding> </melding>]] <elements> ]]>>
         <![CDATA[ <elements> <![CDATA[<melding> </melding>]]> <elements> ]]>
         <![CDATA[ <elements> &lt;![CDATA[<melding> </melding>]]&gt; <elements> ]]>
fatherazrael
  • 5,511
  • 16
  • 71
  • 155

1 Answers1

2

I speculate that your problem is actually being caused by nested CDATA content. Can you try the following:

<![CDATA[
    <DataBatch>
      <DataUnits>
         <DataUnit>
          <FormTask>
           <ServiceCode>323015</ServiceCode>
           <Form>
            <FormData>
                    <![CDATA[
                        <melding> </melding>
                    ]]]]><![CDATA[>
            </FormData>
           </Form>
          </FormTask>
       </DataUnit>
     </DataUnits>
   </DataBatch>
 ]]>

The gist of the trick here is that when the parser hits the inner nested <![CDATA[ it will actually ignore it. Then, when it hits this:

]]]]><![CDATA[>

the first ]] will also be ignored, the following ]]> will be consumed, closing the outer CDATA, and then a new CDATA is immediately opened again which should last until the outer closing for that.

Edit by @fatherazrael:

Remove the XML tags <?xml version="1.0" encoding="UTF-8"?>

Reference: Nested CDATA - correctly

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360