LinqToXml does not handle nillable elements as expected

后端 未结 3 1794
后悔当初
后悔当初 2020-12-20 00:32

According to W3C standards, if you have a nillable element with a nil value, you are supposed to format it like this:



        
3条回答
  •  余生分开走
    2020-12-20 01:03

    LINQ to XML is mostly not schema-aware - it lets you validate the tree, but it doesn't derive any particular semantics from that. Your mistake is believing that null should somehow always map to xsi:nil. There's no such requirement in W3C specs (rather obviously, because they do not cover any kinds of language bindings).

    In particular, XElement constructor that you call actually takes an argument of type object[], which is a list of children - there's no reason why passing null to that should have any relevance to xsi:nil. In any case, how is LINQ to XML supposed to know that you're producing XML that is valid according to some schema, and that one particular element in this schema has nilled="true"?

提交回复
热议问题