Empty element in XML throws error while deserialization

Maheswaran Monoharan 70 Reputation points
2024-03-18T07:42:45.8966667+00:00

I was trying to de-serialize XML elements to an object. In that XML file, there is an empty element like below <enddate/>. It throws incorrect XML file error.

User's image

I tried options like Isnullable, get set method etc. See below

User's image

Still not able to fix it. And the serialize class looks like this

User's image

Why it is not able to parse this empty element ? any method that works?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,177 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiale Xue - MSFT 29,246 Reputation points Microsoft Vendor
    2024-03-18T10:16:50.54+00:00

    Hi @Maheswaran Monoharan , Welcome to Microsoft Q&A,

    You have a few options to choose from, one is to use regex to remove all whitespace elements before parsing, which is in case you don't want it.

    If only one or two specific bits are empty, you can choose to add parsing for them individually.

    For details, you can view Deserialize Xml with empty elements in C#

    Please don't add pictures as questions, it won't make it easier for us to test them.

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful