cancel
Showing results for 
Search instead for 
Did you mean: 

Javascript API question in relation to general javascript

kbonnet
Champ in-the-making
Champ in-the-making
Hi all,

I want to achieve the following. When i check in a XML file into a space, i want a content rule on that space to alter the xml file to add a processing instruction. This processing instruction would be the reference to a XSL stylesheet.

By running a script with the content rule i can write my own javascript. In "normal"  javascript i would have been able to address an XMLDOM object to change the XML file.

Is something like this possible too with the Alfresco Javascript API?

Kind regards,

Koen Bonnet
4 REPLIES 4

pmonks
Star Contributor
Star Contributor
This is possible either using direct string manipulation of the content or via a more strongly typed mechanism such as E4X (http://en.wikipedia.org/wiki/E4X)[1].

Either way, once you've read out the content from the file and modified it, you'd use the Javascript API to write the modified content back into the file (see http://wiki.alfresco.com/wiki/JavaScript_API#Modifying_and_Creating_API for details).

Cheers,
Peter

[1] Note: E4X support has only been enabled in the 2.9 release at this point, but details on how to enable it in earlier versions of Alfresco are in JIRA ticket AR-1720 (http://issues.alfresco.com/browse/AR-1720).

kbonnet
Champ in-the-making
Champ in-the-making
Hi Peter,

Thanks a lot for your reply. I was already working out the string manipulation and writing back, but it seems to me that's not the preferred way to modify xml. I will read into the E4X. That sounds powerful!

Thanks again!

Koen

pmonks
Star Contributor
Star Contributor
No worries!  FWIW I'll often use regular expressions and simple string operations for simple modifications to XML - it's often quicker / easier / faster than pulling out the big guns of a "real" XML parsing engine (such as E4X).

Cheers,
Peter

kbonnet
Champ in-the-making
Champ in-the-making
Thanks. Backed up by the pro's! 🙂