0

I'm using php's SOAPClient class to make SOAP requests and to get SOAP responses, but I need to display the request and response xml on the page for debugging purposes. Problem is, I can't figure out how.

I can use the __getLastRequest() and __getLastResponse() methods to get the xml strings, but I have not found a way to print them out nicely. I did discover that echo'ing out <xmp>[xmlstringhere]</xmp> puts the appropriate xml tags in the string, but there aren't any line breaks, which is a problem since the xml response is HUGE. If only I could get line breaks in the appropriate places, and proper indenting, things would be golden.

Up until now I've been having to copy the outputted xml, save it as a .xml file, and open that. Is there a way to output things in a readable format via php?

hakre
  • 193,403
  • 52
  • 435
  • 836
Nate
  • 26,164
  • 34
  • 130
  • 214
  • 1
    If you let the browser know that you're returning XML (by setting the "content-type" header to "application/xml")), and then dump the XML as your response, any modern browser should show the XML formatted nicely. [Example](http://stackoverflow.com/a/152304/74757) – Cᴏʀʏ Sep 17 '12 at 21:50
  • @Cory - Thanks, but I neglected to mention that I'm outputting other stuff on the page as well. – Nate Sep 17 '12 at 22:01
  • 1
    Perhaps you could drop this gem somewhere in your app and use it as needed? [XML PHP Pretty Printer](http://gdatatips.blogspot.com/2008/11/xml-php-pretty-printer.html) – Cᴏʀʏ Sep 17 '12 at 22:30
  • @Cory -- nice, I will give that a try. – Nate Sep 19 '12 at 21:31

1 Answers1

2

Try echo '<pre>' . $client->__getLastRequest() . '</pre>';

AlienWebguy
  • 76,997
  • 17
  • 122
  • 145