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

294
Visualizações
fast-xml-parser: Build xml with attributes and child elements from json

I'm using fast-xml-parser to create xml documents from json. In the examples they show how to create an element with attributes

const jsOrderedObj = [
    {
        "?textinfo": [
            {
                "#text": ""
            }
        ],
        ":@": {
            "@_whitespace": true,
            "@_is": true,
            "@_allowed": true
        }
    }
];
const options = {
    ignoreAttributes: false,
    preserveOrder: true,
    allowBooleanAttributes: true,
    suppressBooleanAttributes: true
};
const builder = new XMLBuilder(options);
const output = builder.build(result);

result:

<?textinfo   whitespace is allowed?>

And examples of how to create an XML document with child elements:

const xmlData = {
            'foo': {
                'bar': 'data',
                'bar2': 'data2',
                'bar3': 'data3',
                'bar4': 'data4',
            }
        }
const builder = new XMLBuilder({});
const output = builder.build(xmlData);

result:

<foo><bar>data</bar><bar2>data2</bar2><bar3>data3</bar3><bar4>data4</bar4></foo>

Now my question is, how should I define my json, to get both attributes and child elements in my xml, like this:

<foo whitespace is allowed><bar>data</bar><bar2>data2</bar2><bar3>data3</bar3><bar4>data4</bar4></foo>
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