There is xmlencoder in symfony serializer, by using that we achive this.
$data = ['foo' => 'Foo value'];
$encoder = new XmlEncoder();
$encoder->encode($data, 'xml');
// is encoded as follows:
// <?xml version="1.0"?>
// <response>
// <foo>
// Foo value
// </foo>
// </response>
Now we need to add <!DOCTYPE something like below
// is encoded as follows:
// <?xml version="1.0"?>
// <!DOCTYPE response SYSTEM "pathto.dtd">
// <response>
// .....
Is there a way to achieve this with symfony serializer?