Parse XML in JSVM middleware

I have some JSVM middleware where I need to take the request body (which is XML) and parse it into a traversable object that I can work with in the middleware JS code.

What libs are available in the JSVM to do this?

Hi @bitsofinfo, this isn’t currently possible as the JSVM environment is limited to the functions that we expose.

yeah I am evaluating this, have some legacy soap services, need to write some middleware to restrict which methods can be called on a legacy soap service…

You might be able to use a standalone JS library that doesn’t use browser capabilities to parse XML

You could put this code into a MW file, or into the tyk.js file so it is globally available, then call the functions from there (warning, this hasn’t been tested, but we’ve seen users import full crypto NPM modules into our JSVM with some basic modifications, so a long as the library doesn’t rely on browser-specific features, it should work).

Meaning they copied all the code from a NPM module into the tyk.js to make it work?

Yes, we;ll, I think they copied all the code into the MW to get it to work, but tyk.js should work the same.

Though if using node modules, there’s a whole bunch of import stuff that needs to be normalised, so I wouldn’t recommend it unless you are very comfortable with browserify and other node tools to inline code.

But for single-use stuff, that is self contained, copying the code into tyk.js should make it available (so long as there’s no errors!)

has this been handled yet? having a similar challenge