Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to parse XML with Purescript?

Tags:

purescript

I'm looking into functional-programming ways to write a simple web app that does XSLT-like things. I'm thinking about trying Purescript, but I need to make sure it's possible (and relatively easy) to parse XML using it. Is there a way to do that? I found purescript-xml but it seems to be dead (no longer on Pursuit). Am I missing something?

like image 481
Jonathan Avatar asked Jan 24 '26 12:01

Jonathan


1 Answers

I made a simple foreign import for DOMParser and then used the standard DOM library purescript-dom.

There are bindings in purescript-domparser but I didn't care for them. There is no reason I can discern for representing the DOMParser object.

This is what I used:

exports.parseXML = function (s) {
  return new DOMParser().parseFromString(s, 'application/xml');
}

foreign import parseXML :: String -> Document

Unfortunately, DOMParser does not make it straight-forward to determine if parsing failed. On failure, it still returns a valid Document but only contains information about the error.

like image 67
erisco Avatar answered Jan 27 '26 01:01

erisco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!