XML Update

Updating of source XML file consist in :

To do that, you must :

  • define model type of xml into component. Whith this définition, you set XML file source to update. This model definition will force then user who open the component, to select XML file to update :
      <models>
            <model key="struts" type="xml" />
      </models>
  • define whith file element, the XML fragment to insert into source XML file XML.
    • The location where XML fragment must be inserted. This location is filled with XPath expression.
    • The template to use to generate this XML fragment.
      <output>
        <file key="struts" >
            <insert path="/struts/package/action[last()]" position="after" >
                    <template uri="/ftl/struts2/struts.xml/action.ftl" />
            </insert>
        </file>
      </output>

    To set source XML file to update (which is defined into model), key attribute of the file element must refer key attribute of model element.

  • write template which generate XML fragment :
    <action name="${actionName}" 
                    class="${actionClassName}">
      <#if resultType != '' >
      <result type="${resultType}" />
      </#if>
    </action>  

model

Model definition type of xml and with xmlFileToUpdate is done like this :

...
<models>
  <model type="xml" key="xmlFileToUpdate"  />
  ...
</models>
...

file

file element is inside output element. It is able to describe th eupdating to do on source XML file which is defined into model. Updating source XML file with key xmlFileToUpdate :

...
<output>
    <file key="xmlFileToUpdate" >
        ...
    </file>
  </output>
...

insert

insert element is inside file element. It is able to insert XML fragment :

  • into a particulary location of the source XML file. This location is defined with path and position attributes.
  • which is generated with template.
...
  <file key="xmlFileToUpdate" >
    <insert path="..." position="..." >
      <template uri="..." />
    </insert>
  </file>
...

path & position

To set location of the XML fragment (which is generated with template), you must use attributes :

  • path which is XPath expression which must refer to a valid node of the XML file.
  • position compared with the node found by path :
    • XML fragment must be inserted before the found node avec position=before.
    • XML fragment must be inserted inside the found node avec position=inside.
    • XML fragment must be inserted after the found node avec position=after.

template

XML fragment to insert is generated. This generation can be done with template (Freemarker, velocity, XSL,...).

To generate XML fragment with template path_of_myTemplate, insert must contain :

...
<insert path="..." position="..." >
  <template uri="path_of_myTemplate" />
</insert>
...