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

Method parseXml

src/v6/Xml2JsParser.js:44–80  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42 }
43
44 parseXml() {
45 //TODO: Separate TagValueParser as separate class. So no scope issue in node builder class
46
47 //OutputBuilder should be set in XML Parser
48 this.outputBuilder = this.options.OutputBuilder.getInstance(this.options);
49 this.root = { root: true};
50 this.currentTagDetail = this.root;
51
52 while(this.source.canRead()){
53 let ch = this.source.readCh();
54 if (ch === "") break;
55
56 if(ch === "<"){//tagStart
57 let nextChar = this.source.readChAt(0);
58 if (nextChar === "" ) throw new Error("Unexpected end of source");
59
60
61 if(nextChar === "!" || nextChar === "?"){
62 this.source.updateBufferBoundary();
63 //previously collected text should be added to current node
64 this.addTextNode();
65
66 this.readSpecialTag(nextChar);// Read DOCTYPE, comment, CDATA, PI tag
67 }else if(nextChar === "/"){
68 this.source.updateBufferBoundary();
69 this.readClosingTag();
70 // console.log(this.source.buffer.length, this.source.readable);
71 // console.log(this.tagsStack.length);
72 }else{//opening tag
73 this.readOpeningTag();
74 }
75 }else{
76 this.tagTextData += ch;
77 }
78 }//End While loop
79 if(this.tagsStack.length > 0 || ( this.tagTextData !== "undefined" && this.tagTextData.trimEnd().length > 0) ) throw new Error("Unexpected data in the end of document");
80 }
81
82 /**
83 * read closing paired tag. Set parent tag in scope.

Callers 6

parseMethod · 0.95
parseBytesArrMethod · 0.95
fxp.min.jsFile · 0.80
fxparser.min.jsFile · 0.80
parseMethod · 0.80
parseMethod · 0.80

Calls 8

readSpecialTagMethod · 0.95
readClosingTagMethod · 0.95
readOpeningTagMethod · 0.95
getInstanceMethod · 0.45
canReadMethod · 0.45
readChMethod · 0.45
readChAtMethod · 0.45
updateBufferBoundaryMethod · 0.45

Tested by

no test coverage detected