Question

Writing over a feature in an XML file or how to write over an existing feature in a loop?


Badge

I am producing an XML file in a loop. I write one feature formatted as XML at a time. In the next loop execution I wish to write over what is in the file or wipe it out completely and write the current feature. Thanks.


4 replies

Badge +6

Hi @mkumbale,

 

 

I think in order to best assist in this workflow, we need a greater understanding of the logic behind the workflow. What are you trying to accomplish, how will this workflow be implemented; these are the types of questions that will help us understand the nature of your problem.

I could give you some suggestions - for example using a Decelerator to ensure each writer feature is picked up before the XML is re-written, however, this may not be the most beneficial workflow if this is to be uploaded to Server.

If you are able to share with us the logic behind this workspace(for example what is the purpose of needing the XML to only have 1 feature) - will something be consuming this output XML?

Badge

genvarrems-v1.fmwt

I am trying to generate non-spatial data feed to a program in XML format. This data feed is refreshed with new data say once ever 2 minutes. I have created a loop to update the XML data feed (and later plan to add a WorkspacePauser that would pause for 2 minutes, so that way the next loop would be executed after 2 minutes). I generate new XML output with each loop execution. I want the data I have generated in the current loop to completely write over the old data. I have enclosed the FME workspace.

Userlevel 2
Badge +17

Hi @mkumbale, the Text File writer will append entered features to the destination file one by one while the workspace is running, and closes the file finally when the translation completed. It won't overwrite the file while a single translation process.

It would be ideal if you could use an FME Server to schedule a job to run a workspace overwriting XML.

However, as the second best, I think the AttributeFileWriter transformer could be used effectively in your case, if the workspace should be run with FME Desktop. By default, the AttributeFileWriter overwrites the destination file whenever it receives a feature.

Besides, I don't think you need to do that with looping. You can just create (or copy) multiple (e.g. 4) features, control time interval between continuous features with the Decelerator transformer, create an XML document, and then update the file with the AttributeFileWriter.

Badge

Hi @mkumbale, the Text File writer will append entered features to the destination file one by one while the workspace is running, and closes the file finally when the translation completed. It won't overwrite the file while a single translation process.

It would be ideal if you could use an FME Server to schedule a job to run a workspace overwriting XML.

However, as the second best, I think the AttributeFileWriter transformer could be used effectively in your case, if the workspace should be run with FME Desktop. By default, the AttributeFileWriter overwrites the destination file whenever it receives a feature.

Besides, I don't think you need to do that with looping. You can just create (or copy) multiple (e.g. 4) features, control time interval between continuous features with the Decelerator transformer, create an XML document, and then update the file with the AttributeFileWriter.

My sincere apologies for not responding to your answer earlier. Last couple of days were very hectic and thank you responding so quickly. Actually, I decided to do it in a slightly different way using Windows Task Scheduler so that each execution of the workbench will run sequentially periodically. I can also use a batch or command file to embed workbench execution along with renaming or deleting the output file. However, it is nice to know of what you have outlined as well.

 

 

Reply