MCPcopy Create free account
hub / github.com/NaturalIntelligence/fast-xml-parser / parseTextData

Function parseTextData

src/xmlparser/OrderedObjParser.js:151–181  ·  view source on GitHub ↗

* @param {string} val * @param {string} tagName * @param {string|Matcher} jPath - jPath string or Matcher instance based on options.jPath * @param {boolean} dontTrim * @param {boolean} hasAttributes * @param {boolean} isLeafNode * @param {boolean} escapeEntities

(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities)

Source from the content-addressed store, hash-verified

149 * @param {boolean} escapeEntities
150 */
151function parseTextData(val, tagName, jPath, dontTrim, hasAttributes, isLeafNode, escapeEntities) {
152 const options = this.options;
153 if (val !== undefined) {
154 if (options.trimValues && !dontTrim) {
155 val = val.trim();
156 }
157 if (val.length > 0) {
158 if (!escapeEntities) val = this.replaceEntitiesValue(val, tagName, jPath);
159
160 // Pass jPath string or matcher based on options.jPath setting
161 const jPathOrMatcher = options.jPath ? jPath.toString() : jPath;
162 const newval = options.tagValueProcessor(tagName, val, jPathOrMatcher, hasAttributes, isLeafNode);
163 if (newval === null || newval === undefined) {
164 //don't parse
165 return val;
166 } else if (typeof newval !== typeof val || newval !== val) {
167 //overwrite
168 return newval;
169 } else if (options.trimValues) {
170 return parseValue(val, options.parseTagValue, options.numberParseOptions);
171 } else {
172 const trimmedVal = val.trim();
173 if (trimmedVal === val) {
174 return parseValue(val, options.parseTagValue, options.numberParseOptions);
175 } else {
176 return val;
177 }
178 }
179 }
180 }
181}
182
183function resolveNameSpace(tagname) {
184 if (this.options.removeNSPrefix) {

Callers

nothing calls this directly

Calls 3

parseValueFunction · 0.85
replaceEntitiesValueMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected