Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda