Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

129
Views
Reorder XML Key using JavaScript

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!