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?

4
  • 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 Commented Sep 17, 2012 at 21:50
  • @Cory - Thanks, but I neglected to mention that I'm outputting other stuff on the page as well. Commented Sep 17, 2012 at 22:01
  • 1
    Perhaps you could drop this gem somewhere in your app and use it as needed? XML PHP Pretty Printer Commented Sep 17, 2012 at 22:30
  • @Cory -- nice, I will give that a try. Commented Sep 19, 2012 at 21:31

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.