@rgrove/parse-xml 4.0.1 → 4.2.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 (52) hide show
  1. package/README.md +46 -31
  2. package/dist/browser.js +692 -300
  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 +8 -2
  9. package/dist/index.js.map +1 -1
  10. package/dist/lib/Parser.d.ts +53 -6
  11. package/dist/lib/Parser.d.ts.map +1 -1
  12. package/dist/lib/Parser.js +166 -126
  13. package/dist/lib/Parser.js.map +1 -1
  14. package/dist/lib/StringScanner.d.ts +15 -21
  15. package/dist/lib/StringScanner.d.ts.map +1 -1
  16. package/dist/lib/StringScanner.js +63 -86
  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/XmlElement.js.map +1 -1
  30. package/dist/lib/XmlError.d.ts +24 -0
  31. package/dist/lib/XmlError.d.ts.map +1 -0
  32. package/dist/lib/XmlError.js +52 -0
  33. package/dist/lib/XmlError.js.map +1 -0
  34. package/dist/lib/XmlNode.d.ts +20 -1
  35. package/dist/lib/XmlNode.d.ts.map +1 -1
  36. package/dist/lib/XmlNode.js +28 -3
  37. package/dist/lib/XmlNode.js.map +1 -1
  38. package/dist/lib/syntax.d.ts.map +1 -1
  39. package/dist/lib/syntax.js +18 -23
  40. package/dist/lib/syntax.js.map +1 -1
  41. package/dist/lib/types.d.ts +2 -2
  42. package/dist/lib/types.d.ts.map +1 -1
  43. package/package.json +20 -23
  44. package/src/index.ts +3 -0
  45. package/src/lib/Parser.ts +228 -141
  46. package/src/lib/StringScanner.ts +66 -103
  47. package/src/lib/XmlDeclaration.ts +58 -0
  48. package/src/lib/XmlDocument.ts +4 -2
  49. package/src/lib/XmlDocumentType.ts +67 -0
  50. package/src/lib/XmlError.ts +80 -0
  51. package/src/lib/XmlNode.ts +33 -3
  52. package/src/lib/syntax.ts +12 -18
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 v22.10.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.2.0:
170
+ 253 082 ops/s, ±0.16% | fastest
171
+
172
+ fast-xml-parser 4.5.0:
173
+ 127 232 ops/s, ±0.44% | 49.73% slower
165
174
 
166
- libxmljs2 0.30.1 (native):
167
- 74 006 ops/s, ±0.32% | 60.86% slower
175
+ libxmljs2 0.35.0 (native):
176
+ 68 709 ops/s, ±2.77% | slowest, 72.85% slower
168
177
 
169
- xmldoc 1.2.0 (sax-js):
170
- 68 045 ops/s, ±0.08% | slowest, 64.01% slower
178
+ xmldoc 1.3.0 (sax-js):
179
+ 122 345 ops/s, ±0.15% | 51.66% slower
171
180
 
172
- Finished 3 cases!
173
- Fastest: @rgrove/parse-xml 4.0.0
174
- Slowest: xmldoc 1.2.0 (sax-js)
181
+ Finished 4 cases!
182
+ Fastest: @rgrove/parse-xml 4.2.0
183
+ Slowest: libxmljs2 0.35.0 (native)
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.2.0:
189
+ 1 350 ops/s, ±0.18% | 29.5% slower
181
190
 
182
- libxmljs2 0.30.1 (native):
183
- 2 095 ops/s, ±2.68% | fastest
191
+ fast-xml-parser 4.5.0:
192
+ 560 ops/s, ±0.48% | slowest, 70.76% slower
184
193
 
185
- xmldoc 1.2.0 (sax-js):
186
- 459 ops/s, ±0.10% | slowest, 78.09% slower
194
+ libxmljs2 0.35.0 (native):
195
+ 1 915 ops/s, ±2.64% | fastest
187
196
 
188
- Finished 3 cases!
189
- Fastest: libxmljs2 0.30.1 (native)
190
- Slowest: xmldoc 1.2.0 (sax-js)
197
+ xmldoc 1.3.0 (sax-js):
198
+ 824 ops/s, ±0.20% | 56.97% slower
199
+
200
+ Finished 4 cases!
201
+ Fastest: libxmljs2 0.35.0 (native)
202
+ Slowest: fast-xml-parser 4.5.0
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.2.0:
208
+ 109 ops/s, ±0.17% | 40.11% slower
209
+
210
+ fast-xml-parser 4.5.0:
211
+ 48 ops/s, ±0.55% | slowest, 73.63% slower
197
212
 
198
- libxmljs2 0.30.1 (native):
199
- 189 ops/s, ±0.99% | fastest
213
+ libxmljs2 0.35.0 (native):
214
+ 182 ops/s, ±1.16% | fastest
200
215
 
201
- xmldoc 1.2.0 (sax-js):
202
- 39 ops/s, ±0.08% | slowest, 79.37% slower
216
+ xmldoc 1.3.0 (sax-js):
217
+ 73 ops/s, ±0.50% | 59.89% slower
203
218
 
204
- Finished 3 cases!
205
- Fastest: libxmljs2 0.30.1 (native)
206
- Slowest: xmldoc 1.2.0 (sax-js)
219
+ Finished 4 cases!
220
+ Fastest: libxmljs2 0.35.0 (native)
221
+ Slowest: fast-xml-parser 4.5.0
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