Pure XML in PHP

Asked

Viewed 178 times

1

I am making a request to a web service (done in Delphi), by PHP sending an XML and receiving a reply.

What I want is to be able to show XML exactly as it is.

Code I use: $getData is the request XML

$client = new SoapClient("http://192.168.1.164:8080/wsdl/IComanda");
$obj = $client->Requisicao($gtData);
$xml = simplexml_load_string($obj);
print_r ($xml);

Only what I get is similar to this (example taken from PHP):

SimpleXMLElement Object
(
  [title] => Forty What?
  [from] => Joe
  [to] => Jane
  [body] =>
)

How do I view the pure XML received from web service?

1 answer

3


Note that when using simplexml_load_string() you are interpreting the reply XML.

If you want pure XML just use the previous variable:

$client = new SoapClient("http://192.168.1.164:8080/wsdl/IComanda");
$obj = $client->Requisicao($gtData);

// Só para garantir que o código XML será exibido no navegador
header('Content-Type: application/xml; charset=utf-8');

echo $obj;
  • Alysson, I think the browser that is omitting the tags. See how the return with the header().

  • The error that appears in this code is this: error on line 1 at column 2: Starttag: invalid element name

  • I could test the following: var_dump($obj); ?

  • I took header() and echo and did what you said. Perfect. That’s right, thanks man.

Browser other questions tagged

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