How to suppress empty tags in an XML

Hi all!

I am converting from one XML format into another XML format, where my XML structure is as follows.

Hello
199



CAI - CASH AGAINST

I want to suppress the empty values. My output structure should be

Hello
199
CAI - CASH AGAINST

I am using loop over RefTypeCd which has (19,WS,V0,TT,4B,BLT). I have tried by changing genearteRequiredTags value to false in documentToXMLString, but it does not help me. Does anyone has a solution. Any help would be appreciated. Thanks.

Are you passing the documentTypeName in the documenttoxmlstring service? Can you try not to set any input to that which will suppress it?

HTH,
RMG

generateRequiredTag is the right option that would help you to remove empty tags. This requires documentTypeName to be passed. If it still doesn’t happen, the way you are passing input to this service might not be right. Check for the root node whether it is mapped to document or under document

-Senthil

Mr.Senthil it should work both ways and giving required tags to false and document type name some times works unexpected due to the underlying schema/DTD elements forces to be present for null/empty values.

I would say he can try both options with and with out setting docTypeName:

Agreed. :slight_smile:

I am unable to suppress them tried both the ways. :frowning:

What exactly you tried can you elaborate the trying please?

How ever I know there are some rude ways to remove from the xmldata but its all depends on the requirement always required vs not required in the output data.

Hi RMG/Senthil, I am attaching the generated sample XML file can you please provide me the sample code to remove empty XML tags from it as in your previous posts you have mentioned that documentTypeName is not mandatory. Thanks.
Sample.xml (6.65 KB)

I found an alternate solution by mapping them conditionally I think that is not the right approach, tomorrow if we want the null tags to be generated it will become a problem. So I want to see how can we make use of the property generateRequiredTags. Thanks. :slight_smile:

OK sure as long it works custom way:

But these settings are tricky depends on how is your Schema/DTD is defined for the XML.

I will try on the XML if my time allows to test:

Hi RMG!

Could you please provide me the sample code to suppress the empty tags by making use of the property generateRequiredTags. At least for the following sample code in the above XML document.

Hello
199



CAI - CASH AGAINST

Thanks. :slight_smile: