import { XMLParser, XMLBuilder } from "fast-xml-parser";

const input = `

`;

function convert(element) {
  return {
    "@_Name": "MD11_Vistag",
    NODE_NAME: element.Name,
    VIS_CODE: element.Visibility.Parameter.Code,
  };
}

const parser = new XMLParser({
  ignoreAttributes: false,
});
let jObj = parser.parse(input);

const output = [];

if (Array.isArray(jObj.PartInfo)) {
  jObj.PartInfo.forEach((element) => {
    output.push(convert(element));
  });
} else {
  output.push(convert(jObj.PartInfo));
}

const builder = new XMLBuilder({
  ignoreAttributes: false,
  arrayNodeName: "UseTemplate",
  format: true,
});
const xmlContent = builder.build(output);

console.log(xmlContent);
