Skip to main content

Hi all,

I am trying to write an XML with optional attributes. If the attribute is null or missing I don't want to have it in the output xml. I xml attributes, not child elements. When using the regular xml writer, all fme attributes are redirected as child elements and missing attributes are properly removed.

However, when using xml attributes within a xml templater, missing attributes are still there and note removed.

Any idea on how to solve this?

Hi @jpvo,

The XMLFormatter has some XML clean up options, did you try them?


Hi @jpvo,

The XMLFormatter has some XML clean up options, did you try them?

Yes but it's not solving the probelm when dealing with xml attributes as opposed to xml child elements.

 

 


I've had the same issues, which for my specific task I was able to solve using two StringReplacers with the following regular expressions:

<na-zA-Z0-9_]+>\s*</za-zA-Z0-9_]+>

This one removes emtpy tags, e.g. "<tag></tag>"

And to remove emtpy self-closing tags, such as "<tag />":

< a-zA-Z0-9_]+/>

I don't think it's ideal, but at least it works. I'd be glad if someone with a more elegant solution would like to share it here.

Edit: Oh, and I forgot to mention that I'm using the XMLTemplater and not the XML Writer!


I've had the same issues, which for my specific task I was able to solve using two StringReplacers with the following regular expressions:

<na-zA-Z0-9_]+>\s*</za-zA-Z0-9_]+>

This one removes emtpy tags, e.g. "<tag></tag>"

And to remove emtpy self-closing tags, such as "<tag />":

< a-zA-Z0-9_]+/>

I don't think it's ideal, but at least it works. I'd be glad if someone with a more elegant solution would like to share it here.

Edit: Oh, and I forgot to mention that I'm using the XMLTemplater and not the XML Writer!

We solve it using python to create an xml fragment "manually" and an XMLAppender to insert it at the right place.

 

In the attached workspace I will use a regex to remove name=""

 

 


Reply