Skip to content

Commit

Permalink
fix: boolean attribute and comment xml parsing (#738)
Browse files Browse the repository at this point in the history
Co-authored-by: joernflath <[email protected]>
  • Loading branch information
scolladon and joernflath committed Dec 12, 2023
1 parent bc9833d commit 81e65e5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/utils/fxpHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -18,15 +19,22 @@ const JSON_PARSER_OPTION = {
...XML_PARSER_OPTION,
format: true,
indentBy: ' ',
suppressBooleanAttributes: false,
suppressEmptyNode: false,
}

export const asArray = (node: string[] | string) => {
return Array.isArray(node) ? node : [node]
}

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) => {
Expand Down

0 comments on commit 81e65e5

Please sign in to comment.