Getting Meteor to emit XML

Newbie here. Be kind.

I need to retrieve data from a Meteor service in XML format to provide data to an old system which just refuses to handle JSON.

My core need is to convert a JSON string to XML.

xmlbuilder seems promising but although xmlbuilder appears in the list of packages for my application, attempts to reference it come to naught, i.e.

var xml = xmlbuilder.create(“myData”);
gives the error ‘xmlbuilder is not defined’

Attempts to use js2xmlparser just led down an awful sinkhole of Python versions and Visual C++ bits and instructions to contact the supplier, so I’d prefer to stick to xmlbuilder.

Can anybody advise

  • does xmlbuilder still offer a method to convert a JSON string to XML?

  • if so, what do I need to make it available in my project (hint: it’s probably something incredibly simple involving incorrect case)

  • if not, is there an alternative technique or tool which doesn’t take me down that sinkhole?

Looking through the xmlbuilder github you can see they are exposing it by using:

XmlBuilder = Npm.require('xmlbuilder');

This means that the global variable XmlBuilder is what you need:

var xml = XmlBuilder.create("myData");
1 Like

Thanks, I’d baulked at Npm.require as examples now use import rather than require

would something like

import { xmlbuilder } from ‘xmlbuilder’;

be equivalent, or does that have a completely different purpose?

Yes it has the same outcome.