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

293
Views
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
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!