3
votes

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?

1

1 Answers

2
votes

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.