From 81e65e51ea93b9f8bbf7a55a6a947bfe7a93c245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Colladon?= Date: Tue, 12 Dec 2023 14:01:03 +0100 Subject: [PATCH] fix: boolean attribute and comment xml parsing (#738) Co-authored-by: joernflath --- src/utils/fxpHelper.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/utils/fxpHelper.ts b/src/utils/fxpHelper.ts index ad44652f..87adc8e0 100644 --- a/src/utils/fxpHelper.ts +++ b/src/utils/fxpHelper.ts @@ -6,6 +6,7 @@ import { XML_HEADER_TAG_END } from './metadataConstants' import { Config } from '../types/config' const XML_PARSER_OPTION = { + commentPropName: '#comment', ignoreAttributes: false, ignoreNameSpace: false, parseTagValue: false, @@ -18,6 +19,8 @@ const JSON_PARSER_OPTION = { ...XML_PARSER_OPTION, format: true, indentBy: ' ', + suppressBooleanAttributes: false, + suppressEmptyNode: false, } export const asArray = (node: string[] | string) => { @@ -25,8 +28,13 @@ export const asArray = (node: string[] | string) => { } export const xml2Json = (xmlContent: string) => { - const xmlParser = new XMLParser(XML_PARSER_OPTION) - return xmlParser.parse(xmlContent) + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let jsonContent: any = {} + if (xmlContent) { + const xmlParser = new XMLParser(XML_PARSER_OPTION) + jsonContent = xmlParser.parse(xmlContent) + } + return jsonContent } export const parseXmlFileToJson = async (line: string, config: Config) => {