How to read XML document in triggered action
Answeredwe are currently working on a project where we are creating an XML parser. The user uploads an XML file to the document library "Results", a Triggered action is run to extract the data from this file. We are currently looking for a way to read the file data without downloading it. I remember that we solved a similar case here, but I'm not sure how to read the XML document data. Please, do you have any advice for us how to read data from document if we know its URL?
Thank you for your advice.
-
Hi Samuel,
For now, HTTP Request action for Triggered and Scheduled actions does not support reading the SharePoint file content. DOMParser API for XML parsing is not available in our server-side javascript engine during expression evaluation.
I recommend you use Execute Script action in Modern Forms or List Actions, which are executed in the browser and you can readign the file content from SharePoint and use DOMParser interface to parse the XML file content.
Best regards,
Yuriy Stetsyuk
0 -
Hi Yuriy,
of course I understand. We have found a workaround as we can do it via the Action button in the Display form, but it doesn't work on MacOs (please check my last support ticket).For your better understanding of this issue, our client has this XML parser in Power Automate and now we are migrating this solution to Skybow. He has a workflow with dragging and dropping files from Outlook to the Sharepoint document library, and he hates the workflow like downloading a file from Outlook to his computer and then uploading the file via a button in the Display form because there are a lot of steps and clicks.
If you need i can send you our action for uploading and parsing XML file.I think this may be the key future of how to work with documents. Many of our clients use drag and drop SharePoint function, work with third party applications that export data to xml or share link for document library to external people for uploading documents. Therefore, we need to work with documents on the backend more and more often.
Thank you.0 -
Hi Samuel,
We've introduced the feature to load JS files while evaluating expressions in Triggered and Scheduled actions. The limitation is that the JS file needs to be located within the current SharePoint site.
Since DOMParser is not available in background action executions, I recommend using the fast-xml-parser open-source library to convert XML file content into JSON: https://github.com/NaturalIntelligence/fast-xml-parser#readme
The following example demonstrates how to load an XML file and convert its content to JSON:
/// <reference path="SolutionFiles/fxparser.min.js" />
var parser = new XMLParser({
ignoreAttributes : false
});
var xml = [[@Functions.GetFileContent('[[@Web.Url]]/Shared%20Documents/app.xml', false)]];
var json = parser.parse(xml);
return json;The fxparser.min.js file has been uploaded to the SolutionFiles library on the current site, and this library has been added to the solution with the enabled package&publish library content option.
Best regards,
Yuriy Stetsyuk
1
Please sign in to leave a comment.
Comments
3 comments