Can you add additional properties to .NET serialized NULL values?

杀马特。学长 韩版系。学妹 提交于 2019-12-25 12:55:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!