Skip to main content
Solved

How to Automatically Add New Attributes in an XML Template?

  • August 20, 2025
  • 8 replies
  • 103 views

francisco_1988
Contributor
Forum|alt.badge.img+5

Hello everyone,

I am using an XML template like the one below to generate fields dynamically in FME Workbench:

<field> 

<name>cod_imovel</name>

<description>{fme:get-attribute("cod_imovel")}</description>

</field>

<field>

<name>tema</name>

<description>{fme:get-attribute("tema")}</description>

</field>

<field>

<name>dat_atuali</name>

<description>{fme:get-attribute("dat_atuali")}</description>

</field> 

My question is: if a new attribute appears in my source data (for example, atrr_1), is FME able to automatically add a corresponding field like this in the template:

<field> 

<name>atrr_1</name>

<description>{fme:get-attribute("atrr_1")}</description>

</field>

Or do I need to manually edit the template each time a new attribute is added?

Best answer by takashi

See the attached workspace example.

My approach is to use a combination of AttributeExploder and an XQuery expression implemented in XMLTemplater. Assuming that you can keep only required attributes to be populated into the destination XML document.

You need to learn about XQuery language. Good luck!

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.

8 replies

takashi
Celebrity
  • August 20, 2025

Hi ​@francisco_1988 ,

I think it would be possible if there were a naming convention for attribute names to distinguish new attributes and others.

Can you determine if an attribute is a new one according to its name? If you can, how?

[Addition] Alternatively, it might be possible to create XML <field> element for every attribute regardless of whether it's new one or not, if you could keep only attributes to populate into the destination XML.


francisco_1988
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • August 21, 2025

Hi ​@francisco_1988 ,

I think it would be possible if there were a naming convention for attribute names to distinguish new attributes and others.

Can you determine if an attribute is a new one according to its name? If you can, how?

No.

[Addition] Alternatively, it might be possible to create XML <field> element for every attribute regardless of whether it's new one or not, if you could keep only attributes to populate into the destination XML.

Could you give me an example of your approach?

 

 


takashi
Celebrity
  • Best Answer
  • August 21, 2025

See the attached workspace example.

My approach is to use a combination of AttributeExploder and an XQuery expression implemented in XMLTemplater. Assuming that you can keep only required attributes to be populated into the destination XML document.

You need to learn about XQuery language. Good luck!


francisco_1988
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • August 21, 2025

See the attached workspace example.

My approach is to use a combination of AttributeExploder and an XQuery expression implemented in XMLTemplater. Assuming that you can keep only required attributes to be populated into the destination XML document.

You need to learn about XQuery language. Good luck!

Sensational approach! Last question, I promise. In your approach, you used the AttributeExploder. By default, it works with two columns: Attribute and Value. Let's say my dictionary now contains three attributes: name, type, and description. How would this approach look then?


francisco_1988
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • August 21, 2025

See the attached workspace example.

My approach is to use a combination of AttributeExploder and an XQuery expression implemented in XMLTemplater. Assuming that you can keep only required attributes to be populated into the destination XML document.

You need to learn about XQuery language. Good luck!

I’m not sure if I expressed myself clearly, but assuming my file has three fields: name, description, and type, how would the approach using the AttributeExploder work? Since its output is based on only two columns. I tried removing the AttributeExploder and noticed that the XMLTemplater didn’t recognize my fields: name, description, and type. In your approach, is it only possible to work with lists?Another thing I didn’t understand is why, in my example, it’s saving each record of my table with a unique XML.?

 


takashi
Celebrity
  • August 21, 2025

The screenshot in your original question illustrates that you are attempting to convert name and value of each input attribute to values of <name> and <description> elements for each <field>.

I therefore assumed the input dataset should look like this:

However, in you shared Excel dataset, the actual source dataset has three attributes called "name", "type", and "description", as in:

Since the presumption about shcema of input feature in the original question was wrong, the solution would be completely different. AttributeExploder would be unnecessary.

To find an appropriate solution, I would recommend you to firstly learn the XMLTemplater Help, especially the Configuration/Parameters/Sub-Templates section.

 


francisco_1988
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • August 22, 2025

The screenshot in your original question illustrates that you are attempting to convert name and value of each input attribute to values of <name> and <description> elements for each <field>.

I therefore assumed the input dataset should look like this:

However, in you shared Excel dataset, the actual source dataset has three attributes called "name", "type", and "description", as in:

Since the presumption about shcema of input feature in the original question was wrong, the solution would be completely different. AttributeExploder would be unnecessary.

To find an appropriate solution, I would recommend you to firstly learn the XMLTemplater Help, especially the Configuration/Parameters/Sub-Templates section.

 

Your first approach was essential for my process! I just removed the Attribute Explorer and kept the ListBuilder. Thank you very much for your collaboration.


takashi
Celebrity
  • August 23, 2025

Good to hear you got a solution.

For what it's worth, in your case, using sub template might be easier, as I suggested in my last comment.

To find an appropriate solution, I would recommend you to firstly learn the XMLTemplater Help, especially the Configuration/Parameters/Sub-Templates section.


See also the attached workspace example.