Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda