Skip to main content
Sep 4, 2020 8:09 AM UTC
Solved

How to create XML files on local directory

Dear all developers,

I would like to know how to create xml files on local directory like my desktop and I created test code below but it doesn't work. 
Could you kindly let me know how to achieve?
 
================my test code is below.(hide username due to privacy) ====================
var languages = new XML( '<languages type="dynamic"><lang>JavaScript</lang> <lang>Python</lang></languages>');
 
var params = {
   path: "C:\Users\username\Desktop\newXMLFoloder\test.xml",
    content: languages 
};
 
// no return
 me.SaveXML(params);
Sep 9, 2020 4:32 PM UTC

+1 for Mukul's answer.

We don't allow saving files anywhere outside of the FileRepositories for security reasons.

Even if you use an extension to do this, I would expect for any properly secured system that the user under which Tomcat (and subsequently ThingWorx) runs does not have access to write to those folders.

 

4 replies

Sep 7, 2020 8:58 AM UTC

saveXML is a snippet under File repository thing. So if you give the path for file repo and content as XML it will save the file as a XML document in your file repository. For example I have a TestRepo thing with template as FileRepository and if I execute this service on the Thing it give me the required xml in TestRepo of ThingWorx.

 

me.SaveXML({
path: "test1.xml" /* STRING */,
content: '<languages type="dynamic"><lang>JavaScript</lang> <lang>Python</lang></languages>' /* XML */
});

 

After executing above I will get test1.xml in root of my TestRepo folder under ThingworxStorage->repository folder.

 

 

Sep 9, 2020 4:41 AM UTC

Thank you for your reply but I would like to know how to create xml files on local directory not repository folder.

Sep 9, 2020 8:26 AM UTC

Thingworx can save different type of files in it's repository but AFAIK there is no OOTB way to save an xml directly into local. You can write a custom Java extension to either write it into your local or pick from Thingworx repository and move it to your desired local location.

 

Thanks,

Mukul Narang