XML Parser that works for both browser and Node.js?

Viewed 1651

Problem at hand: I have XML on the client side and the server side, but there's no consistent way to parse XML on both sides.

Most browsers have DOMParser. But Node.js doesn't have a built-in XML parser. There are lots of modules for Node.js for XML parsing, but I'm looking for a XML parser API that is consistent for both front-end and back-end. In other words, I'm looking for a XML parsing module that can be used in Node.js like this

const parser = require(magic_library);
const doc = parser.parseFromString(xml_string, 'application/xml');

and also in the browser like this

<script src="magic_library"></script>
<script>
  const doc = parser.parseFromString(xml_string, 'application/xml');
</script>
2 Answers
Related