how to remove empty tags in input xml

Posted by SGB on Stack Overflow See other posts from Stack Overflow or by SGB
Published on 2010-05-21T17:39:28Z Indexed on 2010/05/21 17:50 UTC
Read the original article Hit count: 256

Filed under:
|
|

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

© Stack Overflow or respective owner

Related posts about java

Related posts about Xml