Question

How to update an XML File with another one

  • 31 March 2017
  • 3 replies
  • 7 views

Badge

Hi,

I have two xml files, the first one is made with these informations:

The second one is made with these information :

 

My problem follows:

1 - I have to put the element <TIMSH> present in the second file in the first file at the same place (same <ASE id>. How can i proceed (for 1 <TIMSH>)

2 - I can have many elements <TIMSH> present in the second file for one <ASE id> and i have to update them in the first file at the same place. How to proceed ? (many <TIMSH> to update)

3 - The tree structure is : <ASE><ATT><TIMSH>

Thanks for your help


3 replies

Userlevel 2
Badge +17

HI @philippe33, I would try this.

  1. From the first file, create features [1] each of which has two attributes - one stores a <Ase> element (XML fragment), another one stores the value of <Ase id>.
  2. From the second file, create features [2] each of which has two attributes - one stores a <Timsh> element (XML fragment), another one stores the value of <Ase id>.
  3. Add an XMLUpdater to the workspace, send the features [1] to the Document port, send the features [2] to the Update port, set the <Ase id> attribute to the Group Update Features By parameter, and configure the Updates parameter to insert the <Timsh> element(s) into the required location in the <Ase> element.
  4. Finally re-construct a single XML document consisting of all the resulting <Ase> elements from the XMLUpdater, using the XMLTemplater.
Userlevel 2
Badge +17

HI @philippe33, I would try this.

  1. From the first file, create features [1] each of which has two attributes - one stores a <Ase> element (XML fragment), another one stores the value of <Ase id>.
  2. From the second file, create features [2] each of which has two attributes - one stores a <Timsh> element (XML fragment), another one stores the value of <Ase id>.
  3. Add an XMLUpdater to the workspace, send the features [1] to the Document port, send the features [2] to the Update port, set the <Ase id> attribute to the Group Update Features By parameter, and configure the Updates parameter to insert the <Timsh> element(s) into the required location in the <Ase> element.
  4. Finally re-construct a single XML document consisting of all the resulting <Ase> elements from the XMLUpdater, using the XMLTemplater.
The attached workspace demonstrates how the procedure can be implemented.

 

b16717-xmlupdater-example.fmw (FME 2016.1.3)
Userlevel 2
Badge +17

HI @philippe33, I would try this.

  1. From the first file, create features [1] each of which has two attributes - one stores a <Ase> element (XML fragment), another one stores the value of <Ase id>.
  2. From the second file, create features [2] each of which has two attributes - one stores a <Timsh> element (XML fragment), another one stores the value of <Ase id>.
  3. Add an XMLUpdater to the workspace, send the features [1] to the Document port, send the features [2] to the Update port, set the <Ase id> attribute to the Group Update Features By parameter, and configure the Updates parameter to insert the <Timsh> element(s) into the required location in the <Ase> element.
  4. Finally re-construct a single XML document consisting of all the resulting <Ase> elements from the XMLUpdater, using the XMLTemplater.
This is an example on the XMLXQueryUpdater with an advanced XQuery expression.

 

b16717-xmlxqueryupdater-example.zip (including FME 2016.1 workspace and two xml docs)

 

Reply