Skip to main content
Solved

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


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

View original
Did this help you find an answer to your question?

8 replies

trentatsafe
Safer
Forum|alt.badge.img+6

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
Influencer
  • 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
takashi wrote:

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
david_r wrote:

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
takashi wrote:

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
trentatsafe wrote:

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
david_r wrote:

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

 

 


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings