fast-xml-parser: сборка xml с атрибутами и дочерними элементами из json

Я использую fast-xml-parser для создания XML-документов из json. В примерах показано, как создать элемент с атрибутами

      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);

результат:

      <?textinfo   whitespace is allowed?>

И примеры того, как создать XML-документ с дочерними элементами:

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

результат:

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

Теперь мой вопрос: как мне определить свой json, чтобы получить как атрибуты, так и дочерние элементы в моем xml, например:

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

0 ответов

Другие вопросы по тегам