cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - You can change your system assigned username to something more personal in your community settings. X

how to read and write .xml files in thingworx

AP_9587236
17-Peridot

how to read and write .xml files in thingworx

how to read and write .xml files in thingworx

ACCEPTED SOLUTION
3 REPLIES 3

 Hi,

 

1. Similar questions have been asked before:

2. Article - "How to manipulate XML Files in ThingWorx javascript?": https://www.ptc.com/en/support/article/CS269346

I am trying to convert json code to xml code. I am getting errors for the following code. Help me to fix it. 
js code:

try{
let JSON = "{College:{entry: [{ Student : 'shiv', Roll_No: 12},{ Student : 'yadav',Roll_No: 56}]}}";
let result = OBJtoXML(JSON);

function OBJtoXML(obj) {
var xml = '';
for (var prop in obj) {
xml += obj[prop] instanceof Array ? '' : "<" + prop + ">";
if (obj[prop] instanceof Array) {
for (var array in obj[prop]) {
xml += "<" + prop + ">";
xml += OBJtoXML(new Object(obj[prop][array]));
xml += "</" + prop + ">";
}
} else if (typeof obj[prop] == "object") {
xml += OBJtoXML(new Object(obj[prop]));
} else {
xml += obj[prop];
}
xml += obj[prop] instanceof Array ? '' : "</" + prop + ">";
}
xml = xml.replace(/<\/?[0-9]{1,}>/g, '');
return xml;
}
}catch(e){
logger.error("jsCodeToConvertJsonToXml: error is "+e+" in linenumber "+e.lineNumber);
}

 

errors:

1. error is TypeError: OBJtoXML is not a function, it is undefined. in linenumber 3.

2.  Message ::Unable To Convert From org.mozilla.javascript.UniqueTag to XML

 

 

 

Announcements


Top Tags