Skip to main content
Solved

Deleteing an XML element completely if the value is NULL in XML Templater?

  • August 9, 2017
  • 8 replies
  • 325 views

Forum|alt.badge.img

Hello everybody, i have mapped my sql server table to an xml schema and final output we are getting metadata of tables. To input related Foreignkey information inside metadata we have a field and we mapped it, problem is for many rows we dont have values, we have NULL. From current mapping values are coming and NULL values are creating empty elements in final xml file. Please see the screenshort. We want to delete the total bnr:foreignkey element for NULL values. Please correct my code if someone can help me. Thanks a lot. Looking forward.

Best answer by david_r

You can use an if-clause around the whole block, something like

{
  if (not($fkey eq "")) then
    <bnr:foreignKey>
       ...
    </bnr:foreignKey>
  else
    ""
}

The syntax is explained in the help under the heading "Root template":

http://docs.safe.com/fme/2017.1/html/FME_Desktop_Documentation/FME_Transformers/Transformers/xmltemplater.htm

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

trentatsafe
Safer
Forum|alt.badge.img+6
  • Safer
  • August 9, 2017

Hello @mjoarder_pln

 

 

If the features are associated with incoming FME-feature fields/attributes, you could check for NULL attributes using the Tester transformer.

 

 

There is another method, I want to verify whether or not it is still the recommended way. I will update this post when I talk to the other XML experts.

david_r
Celebrity
  • Best Answer
  • August 9, 2017

You can use an if-clause around the whole block, something like

{
  if (not($fkey eq "")) then
    <bnr:foreignKey>
       ...
    </bnr:foreignKey>
  else
    ""
}

The syntax is explained in the help under the heading "Root template":

http://docs.safe.com/fme/2017.1/html/FME_Desktop_Documentation/FME_Transformers/Transformers/xmltemplater.htm


takashi
Celebrity
  • August 9, 2017

If there were many elements to be removed when empty, it could be easier to add an XMLFormatter and set "Yes" to its "Remove Empty Elements" parameter.


david_r
Celebrity
  • August 9, 2017

If there were many elements to be removed when empty, it could be easier to add an XMLFormatter and set "Yes" to its "Remove Empty Elements" parameter.

Agreed. He will probably also have to set "Whitespace handling" to "Remove excess whitespace" for this to work with the posted example.

Forum|alt.badge.img

You can use an if-clause around the whole block, something like

{
  if (not($fkey eq "")) then
    <bnr:foreignKey>
       ...
    </bnr:foreignKey>
  else
    ""
}

The syntax is explained in the help under the heading "Root template":

http://docs.safe.com/fme/2017.1/html/FME_Desktop_Documentation/FME_Transformers/Transformers/xmltemplater.htm

 

For me this is not working, may be i wrote wrong. 

 

 

{

 

  if (not($fkey eq "NULL")) then

 

  <bnr:foreignKey>

 

  <bnr:MD_ForeignKey>

 

  <bnr:identifier>

 

  <gmd:MD_Identifier>

 

  <gmd:code>

 

  <gco:CharacterString>{fme:get-attribute($fkey)}</gco:CharacterString>

 

  </gmd:code>

 

  </gmd:MD_Identifier>

 

  </bnr:identifier>

 

  <bnr:table>

 

  <gco:CharacterString/>

 

  </bnr:table>

 

  <bnr:column>

 

  <gco:CharacterString/>

 

  </bnr:column>

 

  </bnr:MD_ForeignKey>

 

  </bnr:foreignKey>

 

  else 

 

  ""

 

  }

 


Forum|alt.badge.img

If there were many elements to be removed when empty, it could be easier to add an XMLFormatter and set "Yes" to its "Remove Empty Elements" parameter.

Thanks, I have one parent element to delete, i think this is not the case for XMLFormatter!

 

 


Forum|alt.badge.img

Hello @mjoarder_pln

 

 

If the features are associated with incoming FME-feature fields/attributes, you could check for NULL attributes using the Tester transformer.

 

 

There is another method, I want to verify whether or not it is still the recommended way. I will update this post when I talk to the other XML experts.
thanks , please see the above code, i want to delete the null value XML element segment completely.

 

 


Forum|alt.badge.img

You can use an if-clause around the whole block, something like

{
  if (not($fkey eq "")) then
    <bnr:foreignKey>
       ...
    </bnr:foreignKey>
  else
    ""
}

The syntax is explained in the help under the heading "Root template":

http://docs.safe.com/fme/2017.1/html/FME_Desktop_Documentation/FME_Transformers/Transformers/xmltemplater.htm

My problem has been solved. I made some mistakes in code. Thanks