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

Method parse

src/xmlparser/XMLParser.js:19–39  ·  view source on GitHub ↗

* Parse XML dats to JS object * @param {string|Uint8Array} xmlData * @param {boolean|Object} validationOption

(xmlData, validationOption)

Source from the content-addressed store, hash-verified

17 * @param {boolean|Object} validationOption
18 */
19 parse(xmlData, validationOption) {
20 if (typeof xmlData !== "string" && xmlData.toString) {
21 xmlData = xmlData.toString();
22 } else if (typeof xmlData !== "string") {
23 throw new Error("XML data is accepted in String or Bytes[] form.")
24 }
25
26 if (validationOption) {
27 if (validationOption === true) validationOption = {}; //validate with default options
28
29 const result = validate(xmlData, validationOption);
30 if (result !== true) {
31 throw Error(`${result.err.msg}:${result.err.line}:${result.err.col}`)
32 }
33 }
34 const orderedObjParser = new OrderedObjParser(this.options, this.externalEntities);
35 // orderedObjParser.entityDecoder.setExternalEntities(this.externalEntities);
36 const orderedResult = orderedObjParser.parseXml(xmlData);
37 if (this.options.preserveOrder || orderedResult === undefined) return orderedResult;
38 else return prettify(orderedResult, this.options, orderedObjParser.matcher, orderedObjParser.readonlyMatcher);
39 }
40
41 /**
42 * Add Entity which is not by default supported by this library

Callers

nothing calls this directly

Calls 4

validateFunction · 0.90
prettifyFunction · 0.85
parseXmlMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected