@rgrove/parse-xml 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +40 -25
  2. package/dist/browser.js +642 -223
  3. package/dist/browser.js.map +4 -4
  4. package/dist/global.min.js +9 -8
  5. package/dist/global.min.js.map +4 -4
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +7 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/Parser.d.ts +49 -6
  11. package/dist/lib/Parser.d.ts.map +1 -1
  12. package/dist/lib/Parser.js +133 -102
  13. package/dist/lib/Parser.js.map +1 -1
  14. package/dist/lib/StringScanner.d.ts +5 -5
  15. package/dist/lib/StringScanner.d.ts.map +1 -1
  16. package/dist/lib/StringScanner.js +9 -9
  17. package/dist/lib/StringScanner.js.map +1 -1
  18. package/dist/lib/XmlDeclaration.d.ts +30 -0
  19. package/dist/lib/XmlDeclaration.d.ts.map +1 -0
  20. package/dist/lib/XmlDeclaration.js +36 -0
  21. package/dist/lib/XmlDeclaration.js.map +1 -0
  22. package/dist/lib/XmlDocument.d.ts +4 -2
  23. package/dist/lib/XmlDocument.d.ts.map +1 -1
  24. package/dist/lib/XmlDocument.js.map +1 -1
  25. package/dist/lib/XmlDocumentType.d.ts +37 -0
  26. package/dist/lib/XmlDocumentType.d.ts.map +1 -0
  27. package/dist/lib/XmlDocumentType.js +39 -0
  28. package/dist/lib/XmlDocumentType.js.map +1 -0
  29. package/dist/lib/XmlError.d.ts +24 -0
  30. package/dist/lib/XmlError.d.ts.map +1 -0
  31. package/dist/lib/XmlError.js +52 -0
  32. package/dist/lib/XmlError.js.map +1 -0
  33. package/dist/lib/XmlNode.d.ts +20 -1
  34. package/dist/lib/XmlNode.d.ts.map +1 -1
  35. package/dist/lib/XmlNode.js +28 -3
  36. package/dist/lib/XmlNode.js.map +1 -1
  37. package/dist/lib/syntax.d.ts.map +1 -1
  38. package/dist/lib/syntax.js +1 -1
  39. package/dist/lib/syntax.js.map +1 -1
  40. package/dist/lib/types.d.ts +2 -2
  41. package/dist/lib/types.d.ts.map +1 -1
  42. package/package.json +20 -18
  43. package/src/index.ts +3 -0
  44. package/src/lib/Parser.ts +195 -118
  45. package/src/lib/StringScanner.ts +10 -10
  46. package/src/lib/XmlDeclaration.ts +58 -0
  47. package/src/lib/XmlDocument.ts +4 -2
  48. package/src/lib/XmlDocumentType.ts +67 -0
  49. package/src/lib/XmlError.ts +80 -0
  50. package/src/lib/XmlNode.ts +33 -3
  51. package/src/lib/syntax.ts +1 -1
package/README.md CHANGED
@@ -38,7 +38,7 @@ Or, if you like living dangerously, you can load [the minified bundle](https://u
38
38
 
39
39
  ## Not Features
40
40
 
41
- This parser currently discards document type declarations (`<!DOCTYPE ... >`) and all their contents, because they're rarely useful and some of their features aren't safe when the XML being parsed comes from an untrusted source.
41
+ While this parser is capable of parsing document type declarations (`<!DOCTYPE ... >`) and including them in the node tree, it doesn't actually do anything with them. External document type definitions won't be loaded, and the parser won't validate the document against a DTD or resolve custom entity references defined in a DTD.
42
42
 
43
43
  In addition, the only supported character encoding is UTF-8 because it's not feasible (or useful) to support other character encodings in JavaScript.
44
44
 
@@ -149,64 +149,79 @@ Also, it was fun.
149
149
 
150
150
  ## Benchmark
151
151
 
152
- Here's how parse-xml stacks up against two comparable libraries, [libxmljs2](https://github.com/marudor/libxmljs2) (which is based on the native libxml library) and [xmldoc](https://github.com/nfarina/xmldoc) (which is based on [sax-js](https://github.com/isaacs/sax-js)).
152
+ Here's how parse-xml's performance stacks up against a few comparable libraries:
153
+
154
+ - [fast-xml-parser](https://github.com/NaturalIntelligence/fast-xml-parser), which claims to be the fastest pure JavaScript XML parser
155
+ - [libxmljs2](https://github.com/marudor/libxmljs2), which is based on the native libxml library written in C
156
+ - [xmldoc](https://github.com/nfarina/xmldoc), which is based on [sax-js](https://github.com/isaacs/sax-js)
153
157
 
154
158
  While libxmljs2 is faster at parsing medium and large documents, its performance comes at the expense of a large C dependency, no browser support, and a [history of security vulnerabilities](https://www.cvedetails.com/vulnerability-list/vendor_id-1962/product_id-3311/Xmlsoft-Libxml2.html) in the underlying libxml2 library.
155
159
 
160
+ In these results, "ops/s" refers to operations per second. Higher is faster.
161
+
156
162
  ```
157
- Node.js v18.9.1 / Darwin arm64
163
+ Node.js v18.14.0 / Darwin arm64
158
164
  Apple M1 Max
159
165
 
160
166
  Running "Small document (291 bytes)" suite...
161
167
  Progress: 100%
162
168
 
163
- @rgrove/parse-xml 4.0.0:
164
- 189 074 ops/s, ±0.10% | fastest
169
+ @rgrove/parse-xml 4.1.0:
170
+ 191 553 ops/s, ±0.10% | fastest
171
+
172
+ fast-xml-parser 4.1.1:
173
+ 142 565 ops/s, ±0.11% | 25.57% slower
165
174
 
166
- libxmljs2 0.30.1 (native):
167
- 74 006 ops/s, ±0.32% | 60.86% slower
175
+ libxmljs2 0.31.0 (native):
176
+ 74 646 ops/s, ±0.30% | 61.03% slower
168
177
 
169
178
  xmldoc 1.2.0 (sax-js):
170
- 68 045 ops/s, ±0.08% | slowest, 64.01% slower
179
+ 66 823 ops/s, ±0.09% | slowest, 65.12% slower
171
180
 
172
- Finished 3 cases!
173
- Fastest: @rgrove/parse-xml 4.0.0
181
+ Finished 4 cases!
182
+ Fastest: @rgrove/parse-xml 4.1.0
174
183
  Slowest: xmldoc 1.2.0 (sax-js)
175
184
 
176
185
  Running "Medium document (72081 bytes)" suite...
177
186
  Progress: 100%
178
187
 
179
- @rgrove/parse-xml 4.0.0:
180
- 1 066 ops/s, ±0.11% | 49.12% slower
188
+ @rgrove/parse-xml 4.1.0:
189
+ 1 065 ops/s, ±0.11% | 49.81% slower
181
190
 
182
- libxmljs2 0.30.1 (native):
183
- 2 095 ops/s, ±2.68% | fastest
191
+ fast-xml-parser 4.1.1:
192
+ 637 ops/s, ±0.12% | 69.98% slower
193
+
194
+ libxmljs2 0.31.0 (native):
195
+ 2 122 ops/s, ±2.48% | fastest
184
196
 
185
197
  xmldoc 1.2.0 (sax-js):
186
- 459 ops/s, ±0.10% | slowest, 78.09% slower
198
+ 444 ops/s, ±0.36% | slowest, 79.08% slower
187
199
 
188
- Finished 3 cases!
189
- Fastest: libxmljs2 0.30.1 (native)
200
+ Finished 4 cases!
201
+ Fastest: libxmljs2 0.31.0 (native)
190
202
  Slowest: xmldoc 1.2.0 (sax-js)
191
203
 
192
204
  Running "Large document (1162464 bytes)" suite...
193
205
  Progress: 100%
194
206
 
195
- @rgrove/parse-xml 4.0.0:
196
- 91 ops/s, ±0.11% | 51.85% slower
207
+ @rgrove/parse-xml 4.1.0:
208
+ 93 ops/s, ±0.10% | 53.27% slower
209
+
210
+ fast-xml-parser 4.1.1:
211
+ 48 ops/s, ±0.60% | 75.88% slower
197
212
 
198
- libxmljs2 0.30.1 (native):
199
- 189 ops/s, ±0.99% | fastest
213
+ libxmljs2 0.31.0 (native):
214
+ 199 ops/s, ±1.47% | fastest
200
215
 
201
216
  xmldoc 1.2.0 (sax-js):
202
- 39 ops/s, ±0.08% | slowest, 79.37% slower
217
+ 38 ops/s, ±0.09% | slowest, 80.9% slower
203
218
 
204
- Finished 3 cases!
205
- Fastest: libxmljs2 0.30.1 (native)
219
+ Finished 4 cases!
220
+ Fastest: libxmljs2 0.31.0 (native)
206
221
  Slowest: xmldoc 1.2.0 (sax-js)
207
222
  ```
208
223
 
209
- See the [parse-xml-benchmark](https://github.com/rgrove/parse-xml-benchmark) repo for instructions on running this benchmark yourself.
224
+ See the [parse-xml-benchmark](https://github.com/rgrove/parse-xml-benchmark) repo for instructions on how to run this benchmark yourself.
210
225
 
211
226
  ## License
212
227