1

I'm trying to resolve a problem, where a web service returns 2 XML start tag.

I would like to know if this is normal or if they must solve it:

curl http://url.com/C.asmx/ExecuteFileTransactionSL -d pos="0000" -d fileContent="$(cat "02I - ida.xml")"

XML File:

<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
<Mensaje>
    <EncabezadoMensaje>
        <VersionMsj>ACT20</VersionMsj>
        <TipoMsj>OL</TipoMsj>
        <TipoTransaccion>02I</TipoTransaccion>
        <InicioTrx>
            <FechaTrx>20160704</FechaTrx>
            <HoraTrx>104600</HoraTrx>
        </InicioTrx>
        <Terminal>
            <TipoTerminal>PC</TipoTerminal>
            <NumeroTerminal>60000070</NumeroTerminal>
        </Terminal>
        <Financiador>
            <CodigoFinanciador>OSDE</CodigoFinanciador>
        </Financiador>
        <Prestador>
            <CuitPrestador>30708402911</CuitPrestador>
            <RazonSocial>Sanatorio Prueba</RazonSocial>
        </Prestador>
    </EncabezadoMensaje>
    <EncabezadoAtencion>
        <Credencial>
            <NumeroCredencial>60671956201</NumeroCredencial>
            <ModoIngreso>M</ModoIngreso>
            <CodigoSeguridad>891</CodigoSeguridad>
        </Credencial>
    </EncabezadoAtencion>
</Mensaje>

When I want to parse the response, I get

xml declaration allowed only at the start of the document

This is the reponse:

<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://tempuri.org/">&lt;?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?&gt
;
&lt;Mensaje&gt;
  &lt;EncabezadoMensaje&gt;
    &lt;VersionMsj&gt;ACT20&lt;/VersionMsj&gt;
    &lt;TipoMsj&gt;OL&lt;/TipoMsj&gt;
    &lt;TipoTransaccion&gt;02A&lt;/TipoTransaccion&gt;
    &lt;IdMsj&gt;1095489&lt;/IdMsj&gt;
    &lt;InicioTrx&gt;
      &lt;FechaTrx&gt;20160704&lt;/FechaTrx&gt;
      &lt;HoraTrx&gt;070728&lt;/HoraTrx&gt;
    &lt;/InicioTrx&gt;
    &lt;Terminal&gt;
      &lt;TipoTerminal&gt;PC&lt;/TipoTerminal&gt;
      &lt;NumeroTerminal&gt;60000070&lt;/NumeroTerminal&gt;
    &lt;/Terminal&gt;
    &lt;Financiador&gt;
      &lt;CodigoFinanciador&gt;OSDE&lt;/CodigoFinanciador&gt;
      &lt;SystemTrace&gt;368878    &lt;/SystemTrace&gt;
    &lt;/Financiador&gt;
    &lt;Prestador&gt;
      &lt;CuitPrestador&gt;30708402911&lt;/CuitPrestador&gt;
      &lt;RazonSocial&gt;Sanatorio Prueba&lt;/RazonSocial&gt;
    &lt;/Prestador&gt;
    &lt;GeneradorRespuesta&gt;98&lt;/GeneradorRespuesta&gt;
    &lt;Rta&gt;
      &lt;CodRtaGeneral&gt;00&lt;/CodRtaGeneral&gt;
      &lt;DescripcionRtaGeneral&gt;OK, PRESTACION RE-  GISTRADA            &lt;/DescripcionRtaGeneral
&gt;
      &lt;MensajeDisplay&gt;OK, PRESTACION RE-  GISTRADA            &lt;/MensajeDisplay&gt;
      &lt;MensajePrinter&gt;OK, PREST.REGISTRADAP.2 210     GRAVADO                                 
        &lt;/MensajePrinter&gt;
    &lt;/Rta&gt;
    &lt;NroReferencia&gt;368878    &lt;/NroReferencia&gt;
  &lt;/EncabezadoMensaje&gt;
  &lt;EncabezadoAtencion&gt;
    &lt;Credencial&gt;
      &lt;NumeroCredencial&gt;61510837601         &lt;/NumeroCredencial&gt;
      &lt;VersionCredencial&gt;00&lt;/VersionCredencial&gt;
      &lt;ModoIngreso&gt;M&lt;/ModoIngreso&gt;
      &lt;CodigoSeguridad&gt;891&lt;/CodigoSeguridad&gt;
      &lt;PlanCredencial&gt;2 210&lt;/PlanCredencial&gt;
      &lt;CondicionIVA&gt;G&lt;/CondicionIVA&gt;
    &lt;/Credencial&gt;
    &lt;Preautorizacion&gt;
      &lt;CodigoPreautorizacion&gt;000000&lt;/CodigoPreautorizacion&gt;
    &lt;/Preautorizacion&gt;
    &lt;RtaAdicional&gt;
      &lt;CodigoRtaAdicional&gt;00&lt;/CodigoRtaAdicional&gt;
    &lt;/RtaAdicional&gt;
    &lt;Beneficiario&gt;
      &lt;NombreBeneficiario&gt;FRAGATI MARTIN ARIEL          &lt;/NombreBeneficiario&gt;
      &lt;Sexo&gt;M&lt;/Sexo&gt;
      &lt;FechaNacimiento&gt;19760412&lt;/FechaNacimiento&gt;
    &lt;/Beneficiario&gt;
  &lt;/EncabezadoAtencion&gt;
  &lt;DetalleProcedimientos&gt;
    &lt;CodPrestacion&gt;420101&lt;/CodPrestacion&gt;
    &lt;TipoPrestacion&gt;1&lt;/TipoPrestacion&gt;
    &lt;ArancelPrestacion&gt;0&lt;/ArancelPrestacion&gt;
    &lt;CantidadAprobada&gt;01&lt;/CantidadAprobada&gt;
    &lt;CantidadSolicitada&gt;01&lt;/CantidadSolicitada&gt;
    &lt;DescripcionPrestacion&gt;CONSULTA EN CONSULTORIO&lt;/DescripcionPrestacion&gt;
  &lt;/DetalleProcedimientos&gt;
&lt;/Mensaje&gt;</string>
kjhughes
  • 106,133
  • 27
  • 181
  • 240
JorgeeFG
  • 5,651
  • 12
  • 59
  • 92

1 Answers1

2

As it is, although hideous, your escaped XML string wrapped in a string element is well-formed.

However, somewhere along the line you have an XML declaration (<?xml...?>) other than in the first spot of the document. There may only be at most one XML declaration, and it may only appear at the very top of an XML document. (See Are multiple XML declarations in a document well-formed XML?)

You've not shown us enough to spot the problem for you for sure. It might be that some step in your tool chain is unescaping the &lt;?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?&gt, for example. It might be that you have two XML documents, each with its own XML declaration, combined together. We cannot tell exactly from what you've posted, but this is what to look for.

Update:

Note also that the service that's responding with the escaped XML may be misunderstanding your request. There are some ideas for setting the HTTP headers for Web Services via curl here: Curl command line for consuming webServices?

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240