SheryBulos
5 years agoAce
How to read XML file content?
Hello, Please I want to read an XML file content which exists in the assets in studio? <#assign doc= ${asset.get('/html/assets/companyProducts.xml')}/> ${doc} my intention is to pass this d...
- 5 years ago
SheryBulos Can you try with below java script code
<@liaAddScript> ;(function ($) { $.ajax({ url : '${asset.get('/html/assets/companyProducts.xml')}', type: 'GET', success : function(data){ console.log(data); }, error : function(data){ } }); })(LITHIUM.jQuery); </@liaAddScript>
- 5 years ago
I don't think you can parse XML with Freemarker by itself.
Freemarker is Server-side and JavaScript is client-side, so passing information back and forth between them is difficult.
If you fetched the XML with JS as described above, you could pass the information from it back to the community with and Endpoint.
If you are able to get the data as Json, Freemarker can parse that natively with ?eval. (Note that asset.get just returns a path string, not file contents).
Another helpful tool could be using the http.client context object to make HTTP requests to get file contents. This can only be done in the page init script or in an endpoint (recommended).