Skip to main content
Solved

Question about reading and writing the same XML

  • June 13, 2017
  • 2 replies
  • 52 views

oscard
Influencer
Forum|alt.badge.img+22

Good morning.

I have the XML file of an ATOM feed. That XML has to be updated every time the resources provided by that service are updated. Several dates must be changed.

My first approach is read the XML with the XML reader, calculate the current data, modify the XML using the XMLTemplater and wirting the same XML file using the Text File reader (with "Overwrite" set to YES)..

The process reads the C:/ATOM_feed.xml, edits it and writes the file C:/ATOM_feed.xml.

This doesn't work:

"Error opening dataset 'Text File' for writing, ensure that file path and permissions allow for writing".

I guess it makes sense.

So, in order to avoid this, I have used "Creator" to create a feature with an attribute "join" set to "A". I have added the same attribute to the feed from the XML Reader and I have perfomed a Merge using "FeatureMerger" (Requestor = new feature, Supplier = XML). That way I can read and write the same XML file. The merge is the input of the XML Templater.

But I keep looking at my FME project thinking if there is a "prettier" solution. I tend to miss the simple solution, so... Is there a more elegant way to read and write the same XML file?

Thanks for any help provided!

I'm using FME Desktop 2016.

Best answer by takashi

Hi @oscard, if the update can be done with an XQuery expression, you can use the XMLXQueryUpdater transformer to update the XML file directly.

Alternatively, just inserting a FeatureHolder before writing might be effective to avoid the problem.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

david_r
Celebrity
  • June 13, 2017

I suspect your solution is pretty optimal, simultaneously reading and writing the same file on disk is asking for trouble, so the OS tries its best to discourage you with a built-in mechanism called file locking.

If you want to learn more about file locking, this is a pretty good starting point: https://en.wikipedia.org/wiki/File_locking


takashi
Celebrity
  • Best Answer
  • June 13, 2017

Hi @oscard, if the update can be done with an XQuery expression, you can use the XMLXQueryUpdater transformer to update the XML file directly.

Alternatively, just inserting a FeatureHolder before writing might be effective to avoid the problem.