问题
In .NET, you can serialize a nullable element using XmlElement( IsNullable = true ), which results in this:
<SomeElement xsi:nil="true" />.
However, I need to be able to add xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance after any field that is being nulled out.
Example:
<SomeElement xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
Is this possible?
回答1:
I figured it out. Here is the answer:
[XmlElement(IsNullable = true, Namespace = "http://www.w3.org/2001/XMLSchema-instance")]
来源:https://stackoverflow.com/questions/9639312/can-you-add-additional-properties-to-net-serialized-null-values