I'm having a Json:
[{"S":"a","D":"b"},{"S":"s1","D":"m1"},{"S":"2","D":"3"},{"S":"4","D":"5"}]
And I want it to convert into XML:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Us>
<U1>
<S>a</S>
<D>b</D>
</U1>
<U1>
<S>s1</S>
<D>m1</D>
</U1>
</Us>
I know the php way, first decoding json using Json_decode()
and a bunch of foreach loop
that finally generate XML.
But I want in Drupal way. There is a module serialization
in core of Drupal 8. But don't know how can I take the services from that module in my custom one.
Also, I got a link, How to get it done using symfony, but again it seems like Drupal 8 standards are lacking somewhere by me.
What's the right approach to achieve this in Drupal way.