Code: Select all
let xml = "<ip><results><result><ip>111.222.333.444</ip><host>555.666.777.888</host><isp>Mobile Communications S.A.</isp><city>Some City</city><countrycode>WW</countrycode><countryname>Worldwebia</countryname><latitude>179.99</latitude><longitude>0.00</longitude></result></results></ip>";
global.log(fX2J(xml));
fX2J(xml) {
const json = {};
for (const res of xml.matchAll(/(?:<(\w*)(?:\s[^>]*)*>)((?:(?!<\1).)*)(?:<\/\1>)|<(\w*)(?:\s*)*\/>/gm)) {
const key = res[1] || res[3];
const value = res[2] && fX2J(res[2]);
json[key] = ((value && Object.keys(value).length) ? value : res[2]) || null;
}
return json;
}
EDIT: nevermind, that's too new to be found in Cinnamon 4.2 anyway. Alternatives? None found so far.