I currently have a mixed-up XML payload that needs to follow the exact order of the key. To illustrate, here's the original payload:
<SampleMsg>
<SampleNumber>1201</SampleNumber>
<Dispatch>
<ShippingDate>2021-11-12</ShippingDate>
<Depot>SYDNEY</Depot>
<CarrierName>ALLIED SYD</CarrierName>
</Dispatch>
<Cases>
<Case>
<CaseNumber>123ABC</CaseNumber>
<CaseID>1</CaseID>
</Case>
</Cases>
</SampleMsg>
Here's what I want to get:
<SampleMsg>
<Dispatch>
<Depot>SYDNEY</Depot>
<ShippingDate>2021-11-12</ShippingDate>
<CarrierName>ALLIED SYD</CarrierName>
</Dispatch>
<Cases>
<Case>
<CaseID>1</CaseID>
<CaseNumber>123ABC</CaseNumber>
</Case>
</Cases>
<SampleNumber>1201</SampleNumber>
</SampleMsg>
There's no browser nor library involved, just pure javascript. Is there a way to predefine the payload structure like a java object and then transform the original payload to the formatted one? Or is there a clean code way to achieve this transformation?
I have tried researching xml-parser but every one of them uses some type of library or DOM (Which in my case, I don't have access to). I was thinking of converting to JSON and using JSON Parser, however, converting between these two formats sometimes have its setback (read here) and it's not ideal when there's a large payload involved.
Any opinion would help and be much appreciated.