RemoveIfEmpty Processing Instructions in Generic XML

In an outbound Generic XML template, the Generic XML instruction RemoveIfEmpty makes it possible to remove the open and close tags surrounding a value if there is no value for any one of the attributes in the section.

The RemoveIfEmpty recursive instruction allows you to remove an entire section of the output. This means that if a section has no values for any of the attributes, the section is eliminated from the file. The 'RemoveIfEmpty recursive' tag is useful when a whole section should be excluded when no values are found. It should not be used if the section includes only mandatory attributes since the output would be incomplete.

If the open and close tags of an individual line should remain even when no value is supplied, use the 'Allow empty tags' option, described in the Allow Empty Tags Parameter in Generic XML section here.

Objects

The objects selected for export includes two products, one without either of the optional values (Manufacturer's part Number and T-shirt Size) and the other with only one of the optional attributes.

Template

Choose Generic XML format and provide the following template text in the Sample field.

With RemoveIfEmpty

Copy
<Products>
   <Product>
   <?Record?>
   <ID><?Target?></ID>
   <NAME><?Target?></NAME>
      <mandatoryAttributes>
         <Parent><?Target?></Parent>
         <BrandName><?Target?></BrandName>
         <ProviderGLN><?Target?></ProviderGLN>
      </mandatoryAttributes>
      <optionalAttributes>
         <?RemoveIfEmpty?>
         <PartNo><?Target?></PartNo>
         <Size><?Target?></Size>
      </optionalAttributes>
   </Product>
</Products>    

With 'RemoveIfEmpty recursive'

Copy
<Products>
   <Product>
   <?Record?>
   <ID><?Target?></ID>
   <NAME><?Target?></NAME>
      <mandatoryAttributes>
         <Parent><?Target?></Parent>
         <BrandName><?Target?></BrandName>
         <ProviderGLN><?Target?></ProviderGLN>
      </mandatoryAttributes>
      <optionalAttributes>
         <?RemoveIfEmpty recursive?>
         <PartNo><?Target?></PartNo>
         <Size><?Target?></Size>
      </optionalAttributes>
   </Product>
</Products>    
  • The RemoveIfEmpty and/or 'RemoveIfEmpty recursive' tags are not used below the 'mandatoryAttributes' section since all attributes should be output, even if they are empty.
  • The RemoveIfEmpty and/or 'RemoveIfEmpty recursive' tags are included below the 'optionalAttributes' section since that information is only required if one or more of the targets have values.

Set Allow empty tags to No. If set to Yes, the 'optionalAttributes' section that is using 'RemoveIfEmpty recursive' instruction will output even when all values are blank.

Mapping

Use the Select Attribute aspect for the attribute data targets after ID and Name.

Results

With RemoveIfEmpty

With 'RemoveIfEmpty recursive'