When generating an XML file with Serializer component (in Symfony4) I want to add a custom attribute to the root node but I can't figure out how to.
The docs mention how to name the root node, but not how to add custom attributes.
In my service I have:
use Symfony\Component\Serializer\Serializer;
// ..
// $this->serializer is auto-wired
$this->serializer->serialize($myEntityObjectToSerialize, 'xml', [
'xml_format_output' => true,
'xml_encoding' => 'utf-8',
'xml_root_node_name' => 'document'
]);
This generates:
<?xml version="1.0" encoding="utf-8"?>
<document>
// ...
</document>
But I want something like this:
<?xml version="1.0" encoding="utf-8"?>
<document id="123" lang="Eng">
// ...
</document>
I don't know what I'm missing. Thank you for the help.