()
| 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. |
no test coverage detected