Deserialize Xml with empty elements in C#

Posted by user204086 on Stack Overflow See other posts from Stack Overflow or by user204086
Published on 2010-06-03T12:51:01Z Indexed on 2010/06/03 12:54 UTC
Read the original article Hit count: 164

Filed under:
|
|

Trying to deserialize some xml snippits into objects. The problem is that I'm getting an invalid format on every empy element tag. I can deserialize the object no problem when all of the elements have values. Or the empty elements are ommitted.

Xml Snippit:

<foo>
<propOne>1</propOne>
<propTwo />
</foo>

C# Class:

[Serialilbe()]
public class foo { public foo(){}
[XmlElementAttribute(IsNullable = true)]
public int? propOne {get;set;}
[XmlElementAttribute(IsNullable = true)]
public int? propTwo {get;set;}
}

Is there a setting on the class I can make to adjust the parsing?
or
Is there an easy way I can apply xsl to remove these elements?
or
Should I use regEx to remove the empty elements be fore desrializing?
or
an even better way?

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml