Render Empty XML Elements as Parent Elements

后端 未结 3 691
悲&欢浪女
悲&欢浪女 2021-01-23 17:39

I have a strange requirement where an application consuming some XML that my application is generating actually needs empty elements to be serialized as parent elements. For exa

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 17:47

    Scott Hanselman wrote a while back an article about stripping out empty elements from XML, and at a glance the code can be used for your purpose with a small alteration to the treatment of empty elements. He also explains why using RegEx is a bad idea.

    I am pointing this out, as I don't know of a way to get XmlSerializer to do what you want.

    Another possibility, though I don't really know much about WPF is using the XAML serializer - look at the System.Window.Markup namespace documentation.

提交回复
热议问题