how to read and write .xml files in thingworx
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
how to read and write .xml files in thingworx
how to read and write .xml files in thingworx
Solved! Go to Solution.
- Labels:
-
Best Practices
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
Hi,
1. Similar questions have been asked before:
- "Create & Write data into XML file": https://community.ptc.com/t5/ThingWorx-Developers/create-amp-Write-data-into-XML-file/td-p/573781
- "Using XML Objects": https://community.ptc.com/t5/ThingWorx-Developers/Using-XML-Objects/td-p/523983
2. Article - "How to manipulate XML Files in ThingWorx javascript?": https://www.ptc.com/en/support/article/CS269346
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator
