cancel
Showing results for 
Search instead for 
Did you mean: 

Extract data from xml node

jsc
Champ in-the-making
Champ in-the-making
Hi,

I'm new to Alfresco and I want to extract data from xml.

If I have a file like this :


<dumb:example>
<dumb:content>Alfresco content</dumb:content>
<dumb:text>Alfresco text</dumb:text>
</dumb:example>

I want Alfresco to index contents of dumb:content and dumb:text when I upload this file. In addition what I have to do to make Alfresco gives me these params to be updated in modify content properties page ?

I read a lot of documentation about model and aspect but it's for metadata, isn't it ?

Any help please.
4 REPLIES 4

jsc
Champ in-the-making
Champ in-the-making
After search it seems to be the work of XPathContentWorkerSelector and XPathMetadataExtracter to extract data from xml.

I review my work and test another file.

At first I have this extension

<model name="dumb:dumbmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

   <!– Optional meta-data about the model –>  
   <description>Dumb Model</description>
   <author></author>
   <version>1.0</version>

   <imports>
        <!– Import Alfresco Dictionary Definitions –>
      <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
      <!– Import Alfresco Content Domain Model Definitions –>
      <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
   </imports>

   <!– Introduction of new namespaces defined by this model –>
   <!– NOTE: The following namespace custom.model should be changed to reflect your own namespace –>
   <namespaces>
     <namespace uri="dumb.model" prefix="dumb"/>
   </namespaces>
  
       <types>
      <type name="dumb:example">
         <title>Example model</title>
         <parent>cm:content</parent>
         <properties>
            <property name="dumb:resume">
                <title>Resume</title>
                <type>d:text</type>
                <mandatory>true</mandatory>
            </property>
         </properties>
      </type>
    </types>
     
</model>

In core-services-context.xml :

    <bean id="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
        <property name="models">
            <list>
                <value>alfresco/model/defaultCustomModel.xml</value>
                <value>alfresco/model/customModel.xml</value>
                <value>alfresco/model/dumbExampleModel.xml</value>
            </list>
        </property>
    </bean>

In web-client-config-custom I add this to view the property resume :

     <config evaluator="node-type" condition="dumb:example">
      <property-sheet>
        <show-property name="dumb:resume" display-label-id="resume" ignore-if-missing="false" />
      </property-sheet>
   </config>

And finally in wcm-xml-metadata-extracter-context.xml :


   <bean id="extracter.xml.sample.AlfrescoModelMetadataExtracter"
         class="org.alfresco.repo.content.metadata.xml.XPathMetadataExtracter"
         parent="baseMetadataExtracter"
         init-method="init" >
      <property name="mappingProperties">
         <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="properties">
               <props>
                  <prop key="namespace.prefix.d">http://www.alfresco.org/model/dictionary/1.0</prop>
                  <prop key="resume">d:text</prop>
               </props>
            </property>
         </bean>
      </property>
      <property name="xpathMappingProperties">
         <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
            <property name="properties">
               <props>
                  <prop key="namespace.prefix.dumb">dumb.model</prop>
                  <prop key="resume">/dumb:example/resume/text()</prop>
               </props>
            </property>
         </bean>
      </property>
   </bean>
   <bean
         id="extracter.xml.sample.selector.XPathSelector"
         class="org.alfresco.repo.content.selector.XPathContentWorkerSelector"
         init-method="init">
      <property name="workers">
         <map>
            <entry key="/dumb:example">
               <ref bean="extracter.xml.sample.AlfrescoModelMetadataExtracter" />
            </entry>
         </map>
      </property>
   </bean>
 

  …

If I 'm not mistaken when uploading this file

<?xml version="1.0" encoding="UTF-8"?>
<dumb:example xmlns:alf="http://www.alfresco.org" xmlns:chiba="http://chiba.sourceforge.net/xforms" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:mla="http://www.alfresco.org/alfresco/mla" xmlns:xf="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dumb:resume>resume</dumb:resume>
</dumb:example>

I should view resume property filled in "Modify content property" page.  But it's not the case and I don't know where the trouble is.

If someone has any idea …

jsc
Champ in-the-making
Champ in-the-making
I just put a new rule on my spaces "Extract common metadata fields from content" on XML file.

Still doesn't work …

jsc
Champ in-the-making
Champ in-the-making
OK

The mistake was to set the registry of XmlMetadataExtracter in wcm-xml-metadata-extracter-context.xml

I remove it and it works fine.

Problem solved Smiley Happy

miguel_gil_mart
Champ in-the-making
Champ in-the-making
OK
The mistake was to set the registry of XmlMetadataExtracter in wcm-xml-metadata-extracter-context.xml
I remove it and it works fine.
Problem solved Smiley Happy
Hi!! Could you post the resulting files? Thanks in advance.