Hi Ameer,
Unfortunately there is no built-in DOMParser or XML parser available in Rocket MX engine side JavaScript at the moment.
Are you bound to the import format, or is the format free?
As example, JavaScript is very friendly with JSON. So if the format is free and the structure can be created in JSON instead of XML the code would be relatively easy:
Sample JSON data:
{
"FunctionKeyList": {
"Screens": [
{
"Name" : "Screen1",
"FunctionKeys": [
{
"Fkey": "F1",
"Description": "F1 Description"
}
]
},
{
"Name" : "Screen2",
"FunctionKeys": [
{
"Fkey": "Help",
"Description": "Help"
},
{
"Fkey": "F3",
"Description": "F3 Description"
},
{
"Fkey": "F4",
"Description": "F4 Description"
},
{
"Fkey": "F5",
"Description": "F5 Description"
},
{
"Fkey": "F6",
"Description": "F6 Description"
}
]
}
]
}
}
(And this example could even be simplified by removing the FunctionKeyList directive at start))
The code to read and parse this, could be something like:
/* import the file system api for file handling */
import * as fs from 'mx:fs';
let fullpath = script.environment.pckgdir + 'Resources/sample.json';
let file_contents = fs.readTextFile(fullpath);
let functionkeylist = JSON.parse(file_contents);
let screens = functionkeylist.FunctionKeyList.Screens;
screens.forEach((s) => {
console.log(JSON.stringify(s));
});
The console output would be:
INFO javascript.console - {"Name":"Screen1","FunctionKeys":[{"Fkey":"F1","Description":"F1 Description"}]}
INFO javascript.console - {"Name":"Screen2","FunctionKeys":[{"Fkey":"Help","Description":"Help"},{"Fkey":"F3","Description":"F3 Description"},{"Fkey":"F4","Description":"F4 Description"},{"Fkey":"F5","Description":"F5 Description"},{"Fkey":"F6","Description":"F6 Description"}]}
If the source format needs to be XML (for instance for existing files or for files let me know and I can have a look if we have example code or if there are JavaScript modules available that can help.
Regards,
Roger.