Thursday 27 September 2018

Handle Null or Not Present tags in xml file in BI Publisher

Workaround Option 2 in RTF template
If using RTF templates another option is to use a conditional IF at the template level to verify the presence of a certain tag in the XML source.
Within the XML data there are three possible scenarios for the value of an element:
  • The element is present in the XML data, and it has a value
  • The element is present in the XML data, but it does not have a value
  • The element is not present in the XML data, and therefore there is no value
In the RTF template, specify a different behavior depending on the presence of the element and its value. The following examples show how to check for each of these conditions using an "if" statement.
  • To define behavior when the element is present and the value is not null, use the following:
<?if:element_name!=''?> desired behavior <?end if?>
  • To define behavior when the element is present, but is null, use the following:
<?if:element_name and element_name="?> desired behavior <?end if?>
  • To define behavior when the element is not present, use the following:
<?if:not(element_name)?> desired behavior <?end if?>

<?if:not(//G_TAX/TAX_CODE)?>VAT<?end if?>


Example below checks the presence of a XML tag in the source
<?if:not(tag_name)?>tag not found<?end if?><?if:tag_name?><?tag_name?><?end if?>
If the tag tag_name is NOT present in the XML Source, text 'tag not found' will print on the output. If the tag is present, then the value of the tag will print.
Example below prints the value of the tag when its value is not null

<?if:Sold_To_Addr_Line_3_ID53!=''?><?Sold_To_Addr_Line_3_ID53?><?end if?>

No comments:

Post a Comment