I have some xml like the following:
<ClinicalDocument>
<recordTarget>
<patientRole>
<id root="123" />
<id root="456" />
<addr> 999 Hollow Drive </addr>
</patientRole>
</recordTarget>
</ClinicalDocument>
I need to remove one of the ids. I do that with this line of code:
message.removeAllNodes("/ClinicalDocument/recordTarget/patientRole/id[@root='456']");
This results in this:
<ClinicalDocument>
<recordTarget>
<patientRole>
<id root="123" />
<addr> 999 Hollow Drive </addr>
</patientRole>
</recordTarget>
</ClinicalDocument>
This leaves a blank line that the receiving system can not handle. I tried using this code to remove the whitespace but it would not work:
message.setNode('/ClinicalDocument/recordTarget/patientRole', StringUtils.deleteWhiteSpace(message.getNode('/ClinicalDocument/recordTarget/patientRole')));
but it ends up creating bad XML:
<ClinicalDocument>
<recordTarget>
<patientRole><patientRole><idroot="123"/><addr>999HollowDrive</addr></patientRole>
<id root="123" />
<addr> 999 Hollow Drive </addr>
</patientRole>
</recordTarget>
</ClinicalDocument>
In addition duplicating and converting the "<" and ">" to "<" and ">", it remove the space that is needed between the "id" element and the "root" attribute.
I see the removeWhitespace on message but I can't figure out the syntax to use it. Will this help?