Solved

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

  • 9 August 2017
  • 8 replies
  • 40 views

Badge

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.

icon

Best answer by david_r 9 August 2017, 11:41

View original

8 replies

Badge +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.
Userlevel 4

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

Userlevel 2
Badge +17

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.

Userlevel 4

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.
Badge

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 

 

  ""

 

  }

 

Badge

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!

 

 

Badge

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.

 

 

Badge

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

 

 

Reply