I am generating XML in my c#, when I have few empty tags for example,
new XElement("TransLogID", "")
some of those gets rendered as
<TransLogID></TransLogID>
while some of those gets rendered as
<TransLogID/>
What controls when the tags will be expanded and when not? How can I force them to be in a behavior I want?
I think they have different origins.
Root.Add(new XElement("TransLogID1", ""));
Root.Add(new XElement("TransLogID2"));
will give
<TransLogID1></TransLogID1>
<TransLogID2/>
Both elements will have empty Elements/Nodes collections, the subtle difference is that the TransLogID2 will have IsEmpty=true.
If your content is an empty string (new XElement("TransLogID", "")
), it will render as
<TransLogID></TransLogID>
But if it is null (new XElement("TransLogID", null)
), it will render as
<TransLogID/>
Are you sure you're always generating the nodes the same way?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With