JDE E1 Orchestrator - parse XML to JSON with Jruby

245 Views Asked by At

I have this XML; https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml and i need to parse to generate a JSON. I have this template

require 'json'
require 'rexml/document'
include REXML

def main(orchAttr, inputMap)
    jsonIn = JSON.parse(inputMap) 
    jsonOut = JSON.parse("{}") 
    
    #XML Example
    #xml_str = jsonIn["response"] 
    #doc = Document.new(xml_str)  
    #city = doc.elements["AddressValidateResponse/Address/City"].text
    #jsonOut["city"] = city
    
    return JSON.generate(jsonOut)
end

but when I did some modifications, I got an error.

I modified this line

#city = doc.elements["AddressValidateResponse/Address/City"].text

with the XML elements

1

There are 1 best solutions below

0
On

why don't you use ecb api rest? it's useful for orchestrator process and you can get exchange rate and add to P0015A with a form request https://sdw-wsrest.ecb.europa.eu/help/