We have to send xml to a black box processor which does not handle contracted empty elements properly, and of course, which we can’t change directly.
If we send:
<element />
We get back:
<element>\n</element>
which renders as
<element>
</element>
which causes our customers processes to react badly
We should (need to) get back:
<element></element>
When we send over:
<element></element>
the result is as desired, so we need to send
<element></element>
not
to the black box.
When examining the attributes of the empty elements we noted that
<element />
registered isEmpty == true while
<element></element>
registered isEmpty as false, so as an attempted hack we ran this loop:
foreach (XElement feature in _xDocument.Descendants("feature").Where(feature => feature.Element("expiry").IsEmpty))
{
feature.Element("expiry").Value = string.Empty;
}
And in debugging we determined that isEmpty became false, and in debugging environment when sending this to the black box, all was well, but when we deploy to our dev server (and test and prod of course), we still end up seeing output from the black box as if the tags are going over as empty.
How can we force all empty elements in an XML document to always render as expanded tags?
This is a critical bug fix for us at this point – downstream customers are being negatively affected.
Thanks very much!
Look here:
Render Empty XML Elements as Parent Elements