newzad
newzad

Reputation: 704

XML Parsing in Alfresco via Javascript

I want to define a rule in Alfresco -will be a Javascript file- which will get a property of an uploaded XML document and assign that property as a title to that XML document. For instance, the xml file's (myXml) content will be something like this:

<phoneEntry>         
   <name>John Smith</name>         
   <phoneNumber>435522</phoneNumber>    
</phoneEntry>

I will change the title of xml file to John Smith by the rule. I don't know how to write this rule in Javascript. I have been told that Alfresco uses E4X library. Any help will be appreciated.

Upvotes: 1

Views: 991

Answers (2)

Krutik Jayswal
Krutik Jayswal

Reputation: 3175

Share Side Javascript File

    var myConfig = new XML();
    var configNodeRef = getConfigNodeRef("Data%20Dictionary/Configurations/solution_data.xml");

    if (configNodeRef != null) {
            logger.log("create new configNodeRef: " + configNodeRef);


            var configContent = getConfigContent(configNodeRef);


            if (configContent != null && configContent != "") {
              try
              {
                   myConfig = new XML(configContent);
              }
              catch (e)
              {
                 logger.log(e);
              }
            } 

    } 
model.configNodeRef = configNodeRef;

Shre Side Ftl File.

{
"result" : "<#list result as r>${r.label}<#if r_has_next>,</#if></#list>"
}

Portion Of Xml File

<Human_Resources label="Human_Resources">
                <Human_Capital_Management label="Human_Capital_Management" />
                <Payroll label="Payroll" />
                <Talent_Management label="Talent_Management" />
                <HR_Service_Delivery label="HR_Service_Delivery" />
            </Human_Resources>
            <Information_Technology label="Information_Technology">
                <SAP_NetWeaver label="SAP_NetWeaver" />
                <Service_Oriented_Architecture label="Service_Oriented_Architecture" />
                <Enterprise_Mobility label="Enterprise_Mobility" />
                <Cloud_Computing label="Cloud_Computing" />
                <SAP_HANA_and_In_Memory_Computing label="SAP_HANA_and_In_Memory_Computing" />
                <Content_and_Collaboration label="Content_and_Collaboration" />
                <IT_Management label="IT_Management" />
                <Custom_Development label="Custom_Development" />
                <Database label="Database" />
                <SAP_Application_Interface_Framework label="SAP_Application_Interface_Framework" />
            </Information_Technology>

Above example is created in alfresco share for reading xml file from alfresco repository.

Upvotes: 1

newzad
newzad

Reputation: 704

Ok, I have found the solution by myself. I hope this helps someone.

var docXml = new XML(document.content);
document.name = docXml.phoneEntry.name; 

Upvotes: 2

Related Questions