'Add xml attribute documentname

I'm exporting orders to xml I write in the header of XML

 $xml = new SimpleXMLElement('<Document></Document>');
    $xml->addAttribute('documentname','DCustomers');
    $xml->addAttribute('xmlns','http://www.microarea.it/XTech/1.0.0/XMLSchema');

the xml result is

 <?xml version="1.0"?>
    <Document xmlns="http://www.microarea.it/XTech/1.0.0/XMLSchema" documentname="DCustomers">

but the tag is reversed i need documentname="DCustomers" tag before in this way

 <?xml version="1.0"?>
    <Document documentname="DCustomers" xmlns="http://www.microarea.it/XTech/1.0.0/XMLSchema">

how can i do? thanks a lot!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source