aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

Replace "fast-xml-parser" with "@xmldom/xmldom"

Open trivikr opened this issue 3 months ago • 2 comments

Describe the feature

When XML Parser was investigated for AWS SDK for JavaScript (v3) in Jan 2020, we had only compared pixl-xml with fast-xml-parser https://github.com/aws/aws-sdk-js-v3/issues/735#issuecomment-580009806

We hadn't considered other xml parsers back then.

We revisited XML parsing as a follow-up to using native DOMParser in browser in https://github.com/aws/aws-sdk-js-v3/pull/7347 Early benchmarks indicate that @xmldom/xmldom is faster than fast-xml-parser for our use cases https://github.com/trivikr/benchmark-xml-parser

Use Case

Switch to a parser which is compliant with DOMParser, as well as performant

Proposed Solution

Replace "fast-xml-parser" with "@xmldom/xmldom" as:

  • It has faster parsing for our use cases
    • https://github.com/trivikr/benchmark-xml-parser
  • It has more comparable number of downloads
    • Comparisons https://npmtrends.com/@xmldom/xmldom-vs-fast-xml-parser-vs-xml2js
    • Over 70% of fast-xml-parser downloads are from JS SDK v3 https://npmtrends.com/@aws-sdk/core-vs-fast-xml-parser
  • It has smaller install size
    • 179 kB https://packagephobia.com/result?p=%40xmldom%2Fxmldom
    • 578 kB https://packagephobia.com/result?p=fast-xml-parser

The bundle size is slightly bigger

But that won't impact browser applications, where we use DOMParser

Other Information

No response

Acknowledgements

  • [x] I may be able to implement this feature request
  • [ ] This feature might incur a breaking change

SDK version used

N/A

Environment details (OS name and version, etc.)

N/A

trivikr avatar Sep 22 '25 21:09 trivikr

I support this message. We need this in order to not break deployments to Cloudflare workers which struggle with DOMParser errors.

RowanAldean avatar Oct 09 '25 22:10 RowanAldean

This feature request would not help with those errors.

In https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.911.0, DOMParser was removed from module level code so it will no longer try to initialize until you use an actual XML-based SDK Client, such as S3.

We still use fast-xml-parser in the default runtime environment, which is Node.js. If you run in that mode on Cloudflare Workers the SDK will use fast-xml-parser. Replacing it with @xmldom/xmldom would not address any DOMParser errors.

If you run or bundled with a browser-like runtime environment, a global scope DOMParser implementation is required and fast-xml-parser is not used, so this feature request would not change anything there either. @xmldom/xmldom is one option that can provide such a polyfill.

kuhe avatar Oct 29 '25 19:10 kuhe