how to remove empty tags in input xml
- by SGB
My java module gets a huge input xml from a mainframe. Unfortunately, the mainframe is unable to skip optional elements when it is not a leaf node, with the result that I get a LOT of empty tags in my input :
So,
<pre><code><SSN>111111111</SSN>
<Employment>
<Current>
<Address>
<line1/>
<line2/>
<line3/>
<city/>
<state/>
<country/>
</Address>
<Phone>
<phonenumber/>
<countryCode/>
</Phone>
</Current>
<Previous>
<Address>
<line1/>
<line2/>
<line3/>
<city/>
<state/>
<country/>
</Address>
<Phone>
<phonenumber/>
<countryCode/>
</Phone>
</Previous>
</Employment>
<MaritalStatus>Single</MaritalStatus>
</code></pre>
should be
<SSN>111111111</SSN>
<MaritalStatus>Single</MaritalStatus>
I use jaxb to unmarshall the input xml string that the mainframe sends it. Is there a clean/ easy way to remove all the empty group tags, or do I have to do this manuall in the code for each element. I have over 35 elements in my input xml, so I would love to it if jaxb itself had a way of doing this automatically?
Thanks,
SGB