I have an XElement that it outputs
<Email>address@email.com</Email>
. Based on some criteria, I may need to remove the email address and set it to null. I know that I can set set.Value = ""; but it will not do what I want. I want to change it so that the result is as follows:
<Email xsi:nil=\"true\" />
I do not want to create a new node, because this is the node link in the document. and I want to keep the node where it is inside the document. I tried
emailItem.Add(new XAttribute("xsi:nil", "true"));
but I got the following exception
The character ':', the hexadecimal value 0x3A, cannot be included in the name. The following changes create the node almost correctly:
XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
emailItem.Add(new XAttribute(xsi + "nil", true));
emailItem.Value =""; //How do I set to Null?
In the end, I get <Email xsi:nil="true"></Email> <Email xsi:nil="true"/>
source
share