cancel
Showing results for 
Search instead for 
Did you mean: 

Modifying XML file with Business Rule

lblancher
Champ in-the-making
Champ in-the-making
Hello,
  I am looking to update a file in the alfresco system, when another file is uploaded into a drop area, kind of like a historical list of files that pass through a space.  I am currently able to open and update the list file(in plain text format), but I would like to make the list file a xml file that I can apply a template(or style sheet) to.  After reading around the internet i found that Alfresco uses the Rhino Javascript engine from Mozilla.  I have there for looked at XML parsing JavaScript features for Firefox/Mozilla Browers. I have found two methods, but both result in exceptions generated in the alfresco.log file. 

First Method:
xmlDoc=document.implementation.createDocument("","",null);

Result:
TypeError: Cannot call method "createDocument" of undefined

Second Method:
var parser=new DOMParser();
var doc=parser.parseFromString(text,"text/xml");

Result:
ReferenceError: "DOMParser" is not defined.

I am using http://www.w3schools.com/dom/dom_parser.asp as my JavaScript reference for dealing with XML in JavaScript.

How can I resolve these errors? or how can I update a XML file from within  a Business Rule?

Thanks,
Lucas
5 REPLIES 5

gavinc
Champ in-the-making
Champ in-the-making
Rhino uses JavaScript E4X to parse XML, you should therefore be able to do the following:

var book = new XML("<book><chapter>Title</chapter></book>");
var title = book.chapter;

You can learn more about the syntax and possibilities in the links below:

http://www.w3schools.com/e4x/default.asp
http://wso2.org/library/1050

lblancher
Champ in-the-making
Champ in-the-making
I Copy and Pasted the code that you put in your reply.  I now get the error 'ReferenceError: "XML" is not defined.'   Do i have to declare the XML type for use anywhere?

Lucas

gavinc
Champ in-the-making
Champ in-the-making
What version of Alfresco are you using? I'm not sure when we integrated/configured Rhino to use it's E4X support it maybe that you are using a version that doesn't support E4X!

Alternateivly, try using the latest nightly build or the code from SVN.

lblancher
Champ in-the-making
Champ in-the-making
Hi,
  I am using Alfresco Community 2.1 as downloaded from the alfresco web site last week.  When is the next expected stable build with this functionaly scheduled?

Lucas

gavinc
Champ in-the-making
Champ in-the-making
We don't have any confirmed dates for the 2.9 release as yet I'm afraid.