From f8e4234484e5262ca18733a77b598c08cb775012 Mon Sep 17 00:00:00 2001 From: tagoad <43684949+tagoad@users.noreply.github.com> Date: Thu, 5 May 2022 16:15:48 -0500 Subject: [PATCH] Added Selective Parsing of Attributes by Tag Name Modified Options Builder to include new option - attributeTargetTags - Array Modified OrderedObjParser to check for attributeTargetTags and see if TagName is in the array --- src/xmlparser/OptionsBuilder.js | 1 + src/xmlparser/OrderedObjParser.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/xmlparser/OptionsBuilder.js b/src/xmlparser/OptionsBuilder.js index f46d0b21..2f405af1 100644 --- a/src/xmlparser/OptionsBuilder.js +++ b/src/xmlparser/OptionsBuilder.js @@ -10,6 +10,7 @@ const defaultOptions = { //ignoreRootElement : false, parseTagValue: true, parseAttributeValue: false, + attributeTargetTags: [], // Optional Array of Tag Names that will have attributes parsed trimValues: true, //Trim string values of tag and attributes cdataPropName: false, numberParseOptions: { diff --git a/src/xmlparser/OrderedObjParser.js b/src/xmlparser/OrderedObjParser.js index 004845d3..97110502 100644 --- a/src/xmlparser/OrderedObjParser.js +++ b/src/xmlparser/OrderedObjParser.js @@ -122,10 +122,10 @@ function resolveNameSpace(tagname) { const attrsRegx = new RegExp('([^\\s=]+)\\s*(=\\s*([\'"])([\\s\\S]*?)\\3)?', 'gm'); function buildAttributesMap(attrStr, jPath) { - if (!this.options.ignoreAttributes && typeof attrStr === 'string') { + const tagName = jPath.split('.').pop(); + if (!this.options.ignoreAttributes && typeof attrStr === 'string' && (!this.options.attributeTargetTags.length || this.options.attributeTargetTags.includes(tagName))) { // attrStr = attrStr.replace(/\r?\n/g, ' '); //attrStr = attrStr || attrStr.trim(); - const matches = util.getAllMatches(attrStr, attrsRegx); const len = matches.length; //don't make it inline const attrs = {};