Skip to main content

We used an XMLTemplater (2022.2) to generate an xml message using Excel file input with some optional columns.

The XML template contains some if structures like this :

            {

            if (fme:has-attribute("STATUS")) then

<Info>

<keyName>STATUS</keyName>

<value>{fme:get-attribute("STATUS")}</value>

</Info>

            else()

            }

The output xml is correct, but contains empty lines for every missing column, which we want to avoid.

Leaving out the else() clause is not allowed as it results in a parsing error.

How can we avoid those empty lines in the output xml ?

Would it be acceptable to have a generic value there (something along the lines of "no data" or "n/a" or something like that)? If so, you can use a NullAttributeMapper to replace empty or missing values with something of your choosing.


There is no problem with the empty values, the XML content is "correct". It only contains empty lines for any missing optional attribute.

 

Let's say the status column is present but empty and the 3 other optional columns are not present we will get something like

<component>

            <Info>

<keyName>STATUS</keyName>

<value/>

            </Info>

             

             

             

  </component>

 

instead of :

  <component>

<Info>

<keyName>STATUS</keyName>

<value/>

</Info>

  </component>

 


We tried to add an XMLFormatter after the XMLTemplater to remove the empty lines, but it doesn't seem to have an option to remove empty lines.


Hello @ivl​ 

The XMLFormatter is the correct transformer to use. The parameter which should remove the empty lines from generated by the if/else() statements is called Whitespace Handling in the Formatting Options section.

By default, this parameter is set to "Preserve all whitespace". Try changing the parameter value to "Remove excess whitespace" to create the XML output without the empty lines.


We tried this already and it didn't seem to work. An inspector at the output of the XMLFormatter still shows the empty lines.

However, meanwhile we noticed it's a inspector bug. It turns out in reality the XMLFormatter did remove the empty lines, the Inspector doesn't show the real output.


Reply