- var_dump: documentation ( source)
- trim: documentation ( source)
<?php
class MySimpleXMLElement extends SimpleXMLElement
{
public function appendXML($append)
{
if ($append) {
if (strlen(trim((string)$append)) == 0) {
$xml = $this->addChild($append->getName());
} else {
$xml = $this->addChild($append->getName(), (string)$append);
}
var_dump($append);
foreach ($append as $child) {
$xml->appendXML($child);
}
foreach ($append->attributes() as $n => $v) {
$xml->addAttribute($n, $v);
}
}
}
}
$currentPayment = new SimpleXMLElement('<payment></payment>');
$currentPayment->addChild('creditCard');
$currentPayment->creditCard->addChild('cardNumber', 'XXXX0027');
$currentPayment->creditCard->addChild('expirationDate', 'XXXX');
$paymentProfile = new MySimpleXMLElement('<paymentProfile></paymentProfile>');
$paymentProfile->appendXML($currentPayment);
echo $paymentProfile->asXML();