Skip to main content

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.

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.

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


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.


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.

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 

 

  ""

 

  }

 


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!

 

 


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.

 

 


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