@@ -31,32 +31,17 @@ export class Parser {
31
31
*/
32
32
constructor ( xml : string , options : ParserOptions = { } ) {
33
33
let doc = this . document = new XmlDocument ( ) ;
34
- this . scanner = new StringScanner ( xml ) ;
35
34
36
35
this . currentNode = doc ;
37
36
this . options = options ;
37
+ this . scanner = new StringScanner ( xml ) ;
38
38
39
39
if ( this . options . includeOffsets ) {
40
40
doc . start = 0 ;
41
41
doc . end = xml . length ;
42
42
}
43
43
44
- this . startParse ( ) ;
45
- }
46
-
47
- startParse ( ) {
48
- this . scanner . consumeString ( '\uFEFF' ) ; // byte order mark
49
- this . consumeProlog ( ) ;
50
-
51
- if ( ! this . consumeElement ( ) ) {
52
- throw this . error ( 'Root element is missing or invalid' ) ;
53
- }
54
-
55
- while ( this . consumeMisc ( ) ) { } // eslint-disable-line no-empty
56
-
57
- if ( ! this . scanner . isEnd ) {
58
- throw this . error ( 'Extra content at the end of the document' ) ;
59
- }
44
+ this . parse ( ) ;
60
45
}
61
46
62
47
/**
@@ -782,6 +767,24 @@ export class Parser {
782
767
return new XmlError ( message , scanner . charIndex , scanner . string ) ;
783
768
}
784
769
770
+ /**
771
+ * Parses the XML input.
772
+ */
773
+ parse ( ) {
774
+ this . scanner . consumeString ( '\uFEFF' ) ; // byte order mark
775
+ this . consumeProlog ( ) ;
776
+
777
+ if ( ! this . consumeElement ( ) ) {
778
+ throw this . error ( 'Root element is missing or invalid' ) ;
779
+ }
780
+
781
+ while ( this . consumeMisc ( ) ) { } // eslint-disable-line no-empty
782
+
783
+ if ( ! this . scanner . isEnd ) {
784
+ throw this . error ( 'Extra content at the end of the document' ) ;
785
+ }
786
+ }
787
+
785
788
/**
786
789
* Throws an invalid character error if any character in the given _string_
787
790
* isn't a valid XML character.
0 commit comments