This may not be obvious to you, but if you add the same element to another parent element, it will be moved to the DOMDocument .
This can be easily prevented by using the created FullName element as a prototype and clone it for the add operation:
$xml_billing->appendChild(clone $xml_fullname); $xml_shipping->appendChild(clone $xml_fullname);
This does what you tried to achieve if I read your question correctly.
And another hint that I just see: the following two lines:
$xml_fullname = $xml->createElement("FullName"); $xml_fullname->nodeValue = $fullname;
You can write one:
$xml_fullname = $xml->createElement("FullName", $fullname);
Hope this helps.
hakre
source share