1

I'm using PHP5 and it's inbuilt SOAP functionality. I'm catching the SOAP Fault errors, and email myself when one is triggered.

What I really need to do is include the __getLastRequest() and __getLastResponse(), however as these are XML objects, when I try to include them by echoing them into the body of my HTML email, for obvious reasons they don't appear in full.

Is there a function or class I can use to convert these objects into a HTML friendly string?

I've googled this but without any joy. If possible i'd like to avoid using a class external to PHPs own functionality but if needs must i'll have to.

EDITED:

How can I format the following XML so that it gives me an indented browser friendly version?

<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="schemas.xmlsoap.org/soap/envelope/"; xmlns:ns1="example.com/"><SOAP-ENV:Body><ns1:Ad… 0NE</ns1:Postcode><ns1:BuildingName></ns1:BuildingName><ns1:BuildingNo></ns1:BuildingNo><ns1:SubBuilding></ns1:SubBuilding><ns1:Organisation></ns1:Organisation><ns1:Street></ns1:Street><ns1:SubStreet></ns1:SubStreet><ns1:Town></ns1:Town><ns1:District></ns1:District></ns1:address><ns1:AccountName>[email protected]</ns1:AccountName><ns1:Password>password</ns1:Password></ns1:AddressLookupUK></SOAP-ENV:Body></SOAP-ENV:Envelope>

2 Answers 2

2

You could use http://www.php.net/manual/en/book.tidy.php eg:

<?php
$xml = '<?xml version="1.0" encoding="UTF-8"?>...</SOAP-ENV:Envelope>';
$config = array(
            'indent'         => true,
            'output-xml'     => true,
            'input-xml'     => true,
            'wrap'         => '1000');

// Tidy
$tidy = new tidy();
$tidy->parseString($xml, $config, 'utf8');
$tidy->cleanRepair();
echo tidy_get_output($tidy);
?>

but you have to install the php extension first.

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

Comments

0

EDIT:

Basic print out of the xml. You may need to adjust to fit the actual xml it was hard to read since it was posted unformatted. Youll also protentialy need to handle nested elements i suppose which would require you to loop through the children. and i suppose attributes as well if you have any... You can refer to the SimpleXML docs for more detail on this.

foreach($xml->Body as $element => $value)
{
  echo "$element: $children";
}

Umm use htmlspecialchars or htmlentities to encode the string...? that way it will display as "code" in ana html email.

7 Comments

I know of this, but again, the subject is an object not simply a string
Whats a var_dump of the object look like?
Apologies. htmlspecialchars has worked and it now appears as the XML string. Is there a function that can let me spit this out with all it's indents intact?
Just echo it inside a <pre>. That should work assuming the mail client supports the tag... i think most do.
I've got <pre> wrapped round it anyway, but it must be being ignored for some reason.
|

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.