How to read a return xml containing CDATA in PHP

Asked

Viewed 285 times

0

Hello, I’m not very familiar with this kind of feedback on a Soapclient request (by the way, I’m not very familiar with SOAP). The return has an "example]] element, and when I try to read the file, it prints the whole in a single string.

        $url = "http://localhost:12/mtd1/mtd.asmx?wsdl";

    $clientSoap = new SoapClient($url, array('soap_version'   => SOAP_1_2));


    $params = array('Usuario'=>'user', 'Senha'=>'1234', 'limite'=>$ultima);

    $positions = $clientSoap->BuscaEventos($params);

It returns something like:

<BuscarEventosResponse>
    <BuscarEventos>
         <![CDATA[<TeleEvento> <NumeroSequencia>1010</NumeroSequencia></TeleEvento>]]
    </BuscarEventos>
</BuscarEventosResponse>

When listing the child elements of the Search tag, it returns a single string eliminating the children. Could someone assist me in this "problem"?

  • "it returns a single string eliminating the children", could detail this part better?

  • When I receive it, it is in this format <![CDATA[<Teleevent> <Numerosequencia>1</Numerosequencia> <Idseqmsg> 95372 </Idseqmsg></Teleevent>]] picking up by Soapui, by PHP when I print the screen, it returns like this: string(636012) " 1 95372 0 0 1 92 22/12/2018 02:59:09 0 34 E8B69 03. Like a single string

  • Yes, because it is an XML within the string. It appears this way because you tried to display the XML inside an HTML without escaping it. If you want to extract the data from this string, you will need to parse it as XML.

  • Thanks @Anderson Carlos Woss, that’s right, I used new Simplexmlelement value returned and it generated an object with the xml fields.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.