I feel like, as simple as the conversion is, there...
# suitescript
s
I feel like, as simple as the conversion is, there must be a simple library that will handle it better and easier than using
N/xml
b
your best choice is N/xml
your second best choice is using browserify on some npm module that uses a virtual dom like xmldom
the conversion is generally much harder when you do things like support attributes or keep the ordering of the xml elements
s
it's been a while since I last tried to use it (I rarely have to deal with XML). Are there method in N/xml to write an entire object structure or does everything have to be added one node at a time? My actual object is going to have 30-40 keys, and the response will be roughly the same size.
order doesn't matter, and there are no attributes
b
that doesnt really matter, you wont easily find an xml library on npm that says it only handles easy xml
j
on the toXML side could you use AdvancedPDF ? You can send it a JSON object and output XML
s
I could use an advanced template. that's a great idea for the request, actually. Thanks. That only leaves parsing the response, using
N/xml
, which at least minimizes the pain.
well, at least, I think I can. I'll have to test it. I can hope it works.
As simple as the structure is, I wonder if I should just write my own conversion module, since I can make a lot of simplifying assumptions. Each xml node is just a string, and there are no attributes or xml schema types.
b
just pretend its a string and use a string template library
s
Oh, good idea! I already have the Mustache module which I use for some other simple templates.
b
doesnt help for parsing but its generally fine for simple
s
Thanks everyone. I have some good ideas to try out now. I'll see what works. Our company generally avoids XML like the plague, so we very rarely do anything with it here. It seems like most services we integrate with either have a JSON/REST api, or use query params or http parameters.