0

I have protected function with php-code:

$replaceData = array(
        '%userName%' => $order->getUserFullName(),
        '%userEmail%' => $order->getUserEmail(),
        '%userPhone%' => $order->getUserPhone(),
        '%userDeliver%' => $order->getUserDeliverTo(),
        '%orderId%' => $order->getId(),
        '%orderKey%' => $order->getKey(),
        '%orderLink%' => shop_url('cart/view/' . $order->getKey()),
    );

How to save this array to xml-file using simpleXML?

1

1 Answer 1

1

Try to do this:

$replaceData = array(
        '%userName%' => $order->getUserFullName(),
        '%userEmail%' => $order->getUserEmail(),
        '%userPhone%' => $order->getUserPhone(),
        '%userDeliver%' => $order->getUserDeliverTo(),
        '%orderId%' => $order->getId(),
        '%orderKey%' => $order->getKey(),
        '%orderLink%' => shop_url('cart/view/' . $order->getKey()),
    );

$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($replaceData, array ($xml, 'addChild'));
print $xml->asXML();

Correction, try this to save as xml

//Save  as xml
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
foreach($replaceData as $key=>$value)
{
   $em = $doc->createElement($key);       
   $text = $doc->createTextNode($value);
   $em->appendChild($text);
   $root->appendChild($em);

}
$doc->save('file.xml');
Sign up to request clarification or add additional context in comments.

2 Comments

I think "print" is show me content of xml, but i need to save it in server folder.
Yes sorry, just edited but notice that it doesn't use simpleXML

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.