Solved

How to prevent the error"There was an error in xml message"?

Posted on 2008-10-19
21
2,140 Views
Last Modified: 2012-06-27
I am doing serialization and deserialization of an xml file but when i m deserializing.I am able to deserialize string values but when i doing the int,decimal,datetime elements i am getting the above errorCan anyone suggest me how to avoid this?
Serialization and Deserialization Methods:

-----------------------------------------

extReader reader = new StreamReader(fDialog.FileName.ToString());

                string xmlString = reader.ReadToEnd();
 
 

                 XmlDocument doc = new XmlDocument();

                 doc.LoadXml(xmlString);

                XmlNodeReader xmlreader = new XmlNodeReader(doc.DocumentElement);

                XmlSerializer ser = new XmlSerializer(typeof(PatientBillRequest));

                PatientBillRequest objPatientBillRequest = (PatientBillRequest)ser.Deserialize(xmlreader);
 

Xml File Properties

-------------------

 [XmlElement(IsNullable = true)]

    public string OrderSetCode

    {

      get { return m_OrderSetCode; }

      set { m_OrderSetCode = value; }

    }

      [XmlIgnore]

    public DateTime StartDate

    {

      get { return m_StartDate; }

      set { m_StartDate = value; }

    }
 

      [XmlElement(ElementName = "StartDate", IsNullable = true)]

      public string StartDateHandler

      {

          set { if (value != null && value != string.Empty) m_StartDate = Convert.ToDateTime(value); }

      }

Open in new window

0
Comment
Question by:tryokane
  • 11
  • 10
21 Comments
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22755837
Line 31: You should use the XmlConvert instead of the standard Convert.

0
 
LVL 2

Author Comment

by:tryokane
ID: 22756018
No,I have tried its not working.It is not all going to that particular tag at all.
0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22756142
Maybe its the lack of a get; for StartDateHandler. Try adding one.

Is there any reason you are not directly using the StartDate property?
0
 
LVL 2

Author Comment

by:tryokane
ID: 22763858
Is there any other approach i do this.Can anyone tell me?
0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22764297
You could implement IXmlSerializable and read in the xml yourself...


void IXmlSerializable.ReadXml(XmlReader reader)

{

    if (reader.IsEmptyElement)

    {

        reader.Skip();

        return;

    }
 

    reader.ReadStartElement(); //move past container

    while (reader.NodeType != XmlNodeType.EndElement)

    {

        if (reader.NodeType == XmlNodeType.Element)

        {

            switch (reader.Name)

            {

                case "StartDate":

                    this.StartDate = Convert.ToDateTime(reader.ReadElementContentAsString());

                    break;

                case "OrderSetCode":

                    this.OrderSetCode = reader.ReadElementContentAsString();

                    break;

                default:

                    reader.Skip();

                    break;

            }

        }

        else

            reader.Skip();
 

        reader.MoveToContent();

    }
 

    reader.ReadEndElement();

}

Open in new window

0
 
LVL 2

Author Comment

by:tryokane
ID: 22764326
I tried to do this approach but its not working.Shall i need to make any modifications in the below code?
       private int? no;

       

        public int? No

        {

            get { return no; }

            set { no = value; }

        }

Open in new window

0
 
LVL 2

Author Comment

by:tryokane
ID: 22764332
I mean whenever the element No is empty it is leading to an error like"There was an error in the xml message".How can we avoid this?
0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22764414
Coudl you post an example of the xml your serialiser produces
0
 
LVL 2

Author Comment

by:tryokane
ID: 22764464
This is the xml we are using for serialization and deserilization.We are reading this xml by using the code:

TextReader reader = new StreamReader(fDialog.FileName.ToString());
                string xmlString = reader.ReadToEnd();


                 XmlDocument doc = new XmlDocument();
                 doc.LoadXml(xmlString);
                XmlNodeReader xmlreader = new XmlNodeReader(doc.DocumentElement);
                XmlSerializer ser = new XmlSerializer(typeof(PatientBillRequest));
                PatientBillRequest objPatientBillRequest = (PatientBillRequest)ser.Deserialize(xmlreader);

<?xml version="1.0" encoding="utf-8"?>

<PATIENTBILL xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

	

    <HEADER>

    <BillID>G78889</BillID>

    <BillSubmitDate>2008-07-14</BillSubmitDate>

    <BillSubmitTime>02:55:36.82</BillSubmitTime>

    </HEADER>

		

	<PATIENT>

    <PatientID>G879030</PatientID>

    <PatientNumber>900090</PatientNumber>

    <PatientFirstName>Mary</PatientFirstName>

    <PatientFamilyName>Lee</PatientFamilyName>

    <PassportNumber>G889990</PassportNumber>

    <MRNNumber>MR0090</MRNNumber>

    </PATIENT>

	

	<PAYPLN>

    <PayorPlanID>IP10</PayorPlanID>

    <Payor>MediSave</Payor>

    <Plan>Medi120</Plan>

    <PayorRank>3</PayorRank>

    <AccountNumber>AC0900</AccountNumber>

	<BillAmount>12000</BillAmount>

    <BillPercent>10</BillPercent>

    </PAYPLN>

	

	

	<EPISODE>

    <EpisodeID>EP001</EpisodeID>

    <EpisodeNumber>78821</EpisodeNumber>

    <EpisodeType>I</EpisodeType>

    <EpisodeSubType>Inpatient</EpisodeSubType>

    <EpisodeDate>2008-07-07</EpisodeDate>

    <EpisodeTime>12:58:36.40</EpisodeTime>

	<AdmissionLocation>M34</AdmissionLocation>

	<AdmissionCareProvider>89782R</AdmissionCareProvider>

	<AdmissionBedCode>B01</AdmissionBedCode>

    <AdmissionWard>WD001</AdmissionWard>

    <AdmissionBedTypeCode>BD001</AdmissionBedTypeCode>

    <BillingGroupCode>001</BillingGroupCode>

    <BillingSubGroupCode>101</BillingSubGroupCode>

    <AdmissionRoomTypeCode>ADR20</AdmissionRoomTypeCode>

    <PreferredAccomodation>4BED</PreferredAccomodation>

    <DischargeDate>2008-07-14</DischargeDate>

    <DischargeTime>01:23:32.01</DischargeTime>

    <Diagnosis></Diagnosis>

    <Diagnosis></Diagnosis>

    <Diagnosis></Diagnosis>

    <DiagnosisType></DiagnosisType>

    </EPISODE>

	

		

	<IPMOVE>

    <IPMovementID>86894</IPMovementID>

    <DestinationLocation>QuantaTech Holdings Inc.</DestinationLocation>

    <TransferStartDate>2008-07-08</TransferStartDate>

    <TrasnsferStartTime>10:04:12.75</TrasnsferStartTime>

    <TrasnferToBed>T76</TrasnferToBed>

    <TransferToWard>R1478</TransferToWard>

    <TransferToBedType>E5</TransferToBedType>

    <TransferToRoomType>D8</TransferToRoomType>

    </IPMOVE>

	

	<IPMOVE>

    <IPMovementID>14818</IPMovementID>

    <DestinationLocation>YoyoMatix Associates</DestinationLocation>

    <TransferStartDate>2008-07-09</TransferStartDate>

    <TrasnsferStartTime>10:04:12.75</TrasnsferStartTime>

    <TrasnferToBed>K42</TrasnferToBed>

    <TransferToWard>P6637</TransferToWard>

    <TransferToBedType>I4</TransferToBedType>

    <TransferToRoomType>R4</TransferToRoomType>

    </IPMOVE>

	 

	

	<IPTHAN>

    <TheatreID>1</TheatreID>

    <ChargeCode>Y61</ChargeCode>

    <OperationStatus>CANCELLED</OperationStatus>

    <AnaestheticMethod>X2996</AnaestheticMethod>

    <AnaestheticStatus>DONE</AnaestheticStatus>

    <AnaestheticAgent>T5282</AnaestheticAgent>

	<Anaest.StartDate>2008-07-10</Anaest.StartDate>

    <Anaest.StartTime>22:48:08.06</Anaest.StartTime>

    <Anaest.EndDate>2008-07-10</Anaest.EndDate>

    <Anaest.EndTime>23:24:37.11</Anaest.EndTime>

    </IPTHAN>

		

    <IPTHTR>

    <TheatreID>1</TheatreID>

    <Procedure>H8193</Procedure>

    <TableCode>Q30</TableCode>

    <Priority>A57</Priority>

	<TheatreInDate>2008-07-10</TheatreInDate>

    <TheatreInTime>22:48:08.06</TheatreInTime>

    <TheatreOutDate>2008-07-10</TheatreOutDate>

    <TheatreOutTime>23:24:37.11</TheatreOutTime>

    <OperationStatus>CANCELLED</OperationStatus>

	<PACUStartDate>2008-07-10</PACUStartDate>

    <PACUStartTime>22:48:08.06</PACUStartTime>

    <PACUReadyToLeaveDate>2008-07-10</PACUReadyToLeaveDate>

    <PACUReadyToLeaveTime>23:24:37.11</PACUReadyToLeaveTime>

    </IPTHTR>

			

	<ORDITEM>

    <OrderItemRowID>111000</OrderItemRowID>

    <OrderItemCode>AD76778</OrderItemCode>

    <BillingGroupCode>PHARMACY</BillingGroupCode>

    <BillingSubGroupCode>PHARMACY</BillingSubGroupCode>

    <OrderCategory>GENERAL PHARMACY</OrderCategory>

    <OrderSubCategory>CARBOHYDRATES</OrderSubCategory>

    <OrderSetCode></OrderSetCode>

	<StartDate>2008-07-07</StartDate>

    <StartTime></StartTime>

    <EndDate>2008-07-08</EndDate>

    <EndTime>06:30:03.83</EndTime>

    <Quantity></Quantity>

    <OIDuration>12</OIDuration>

    <OIOrderingLocation></OIOrderingLocation>

    <GeneratedOIIndicator>H2233</GeneratedOIIndicator>

	<BillingStatus>I900</BillingStatus>

    <OIReceivingLocation>O1409</OIReceivingLocation>

    <ListPrice>100</ListPrice>

	<ItemPrice></ItemPrice>

	<ManualOverridePrice>1133</ManualOverridePrice>

    <DiscountedAmount>0</DiscountedAmount>

    <PharmacyRafflesClassificationCode>X788</PharmacyRafflesClassificationCode>

	<ClinicLocation>J989</ClinicLocation>

    <ApptID>A7893</ApptID>

	<ApptDate>2008-07-07</ApptDate>

    <ApptTime>11:15:39.26</ApptTime>

   	<ApptStatus>G983</ApptStatus>

	<ArrivalDate>2008-07-07</ArrivalDate>

	<ArrivalTime>03:54:54.35</ArrivalTime>

    <DepartureDate>2008-07-15</DepartureDate>

    <DepartureTime>03:54:54.35</DepartureTime>

    <CareProvider>Surgeon</CareProvider>

    <CareProviderType>Surgeon</CareProviderType>

    <ServiceRendered></ServiceRendered>

    <ServiceTaxCode>X9990</ServiceTaxCode>

    <OIUrgency>I90</OIUrgency>

    </ORDITEM>

	

	<ORDITEM>

    <OrderItemRowID>111001</OrderItemRowID>

    <OrderItemCode>AD78649</OrderItemCode>

    <BillingGroupCode>CONSULTATION</BillingGroupCode>

    <BillingSubGroupCode>IP CONSULTATION</BillingSubGroupCode>

    <OrderCategory>APPOINTMENT</OrderCategory>

    <OrderSubCategory>CONSULTATION</OrderSubCategory>

    <OrderSetCode></OrderSetCode>

    <StartDate>2008-07-07</StartDate>

    <StartTime>21:21:42.81</StartTime>

    <EndDate>2008-07-08</EndDate>

    <EndTime>06:30:03.83</EndTime>

    <Quantity>1</Quantity>

    <OIDuration>12</OIDuration>

    <OIOrderingLocation>O1410</OIOrderingLocation>

    <GeneratedOIIndicator>433</GeneratedOIIndicator>

	<BillingStatus>I900</BillingStatus>

	<OIReceivingLocation>O1410</OIReceivingLocation>

    <ListPrice>1000</ListPrice>

    <ItemPrice>1500</ItemPrice>

	<ManualOverridePrice>112</ManualOverridePrice>

    <DiscountedAmount>0</DiscountedAmount>

    <PharmacyRafflesClassificationCode></PharmacyRafflesClassificationCode>

	<ClinicLocation>J989</ClinicLocation>

    <ApptID>A7897</ApptID>

	<ApptDate>2008-07-07</ApptDate>

    <ApptTime>11:15:39.26</ApptTime>

   	<ApptStatus>G983</ApptStatus>

	<ArrivalDate>2008-07-07</ArrivalDate>

	<ArrivalTime>03:54:54.35</ArrivalTime>

    <DepartureDate>2008-07-15</DepartureDate>

    <DepartureTime>03:54:54.35</DepartureTime>

	<CareProvider>Surgeon</CareProvider>

    <CareProviderType>Surgeon</CareProviderType>

    <ServiceRendered></ServiceRendered>

    <ServiceTaxCode>X9990</ServiceTaxCode>

    <OIUrgency>I90</OIUrgency>

    </ORDITEM>

	

	<ORDITEM>

    <OrderItemRowID>111002</OrderItemRowID>

    <OrderItemCode>AD78623</OrderItemCode>

    <BillingGroupCode>EXAMINATIONS</BillingGroupCode>

    <BillingSubGroupCode>MEDICAL EXAMINATIONS</BillingSubGroupCode>

    <OrderCategory>EXAMINATIONS</OrderCategory>

    <OrderSubCategory>MEDICAL EXAMINATIONS</OrderSubCategory>

    <OrderSetCode></OrderSetCode>

    <StartDate>2008-07-07</StartDate>

    <StartTime>21:21:42.81</StartTime>

    <EndDate>2008-07-08</EndDate>

    <EndTime>06:30:03.83</EndTime>

    <Quantity>1</Quantity>

		<OIDuration>12</OIDuration>

	 <OIOrderingLocation>O1448</OIOrderingLocation>

    <GeneratedOIIndicator>432</GeneratedOIIndicator>

    <BillingStatus>I900</BillingStatus>

    <OIReceivingLocation>O1448</OIReceivingLocation>

    <ListPrice>500</ListPrice>

	<ItemPrice>1000</ItemPrice>

	<ManualOverridePrice></ManualOverridePrice>

    <DiscountedAmount>0</DiscountedAmount>

    <PharmacyRafflesClassificationCode></PharmacyRafflesClassificationCode>

    <ApptID>A7898</ApptID>

	<ApptDate>2008-07-07</ApptDate>

	<ApptTime>11:15:39.26</ApptTime>

   	<ApptStatus>G983</ApptStatus>

	<ArrivalDate>2008-07-07</ArrivalDate>

	<ArrivalTime>03:54:54.35</ArrivalTime>

    <DepartureDate>2008-07-15</DepartureDate>

    <DepartureTime>03:54:54.35</DepartureTime>

    <CareProvider>Surgeon</CareProvider>

    <CareProviderType>Surgeon</CareProviderType>

    <ServiceRendered></ServiceRendered>

    <ServiceTaxCode>X9990</ServiceTaxCode>

    <OIUrgency>I90</OIUrgency>

    </ORDITEM>

	

	<ORDITEM>

    <OrderItemRowID>111003</OrderItemRowID>

    <OrderItemCode>AD78650</OrderItemCode>

    <BillingGroupCode>FEES</BillingGroupCode>

    <BillingSubGroupCode>FACILITY FEES</BillingSubGroupCode>

    <OrderCategory>FEES</OrderCategory>

    <OrderSubCategory>FACILITY FEES</OrderSubCategory>

    <OrderSetCode></OrderSetCode>

    <StartDate>2008-07-07</StartDate>

    <StartTime>21:21:42.81</StartTime>

    <EndDate>2008-07-08</EndDate>

    <EndTime>06:30:03.83</EndTime>

    <Quantity>2</Quantity>

	<OIDuration>12</OIDuration>

    <OIOrderingLocation>O1412</OIOrderingLocation>

    <GeneratedOIIndicator>431</GeneratedOIIndicator>

    <BillingStatus></BillingStatus>

    <OIReceivingLocation>O1412</OIReceivingLocation>

    <ListPrice>200</ListPrice>

	<ItemPrice>500</ItemPrice>

	<ManualOverridePrice></ManualOverridePrice>

    <DiscountedAmount>0</DiscountedAmount>

    <PharmacyRafflesClassificationCode></PharmacyRafflesClassificationCode>

    <ApptID>A7899</ApptID>

	<ApptDate>2008-07-07</ApptDate>

    <ApptTime>11:15:39.26</ApptTime>

   	<ApptStatus>G983</ApptStatus>

	<ArrivalDate>2008-07-07</ArrivalDate>

	<ArrivalTime>03:54:54.35</ArrivalTime>

    <DepartureDate>2008-07-15</DepartureDate>

    <DepartureTime>03:54:54.35</DepartureTime>

    <CareProvider>Surgeon</CareProvider>

    <CareProviderType>Surgeon</CareProviderType>

    <ServiceRendered></ServiceRendered>

    <ServiceTaxCode>X9990</ServiceTaxCode>

    <OIUrgency>I90</OIUrgency>

    </ORDITEM>

	

	<ORDITEM>

    <OrderItemRowID>111004</OrderItemRowID>

    <OrderItemCode>AD423424</OrderItemCode>

    <BillingGroupCode>PROCEDURES</BillingGroupCode>

    <BillingSubGroupCode>MEDICAL PROCEDURE</BillingSubGroupCode>

    <OrderCategory>PROCEDURES</OrderCategory>

    <OrderSubCategory>MEDICAL PROCEDURE</OrderSubCategory>

    <OrderSetCode></OrderSetCode>

    <StartDate>2008-07-07</StartDate>

    <StartTime>21:21:42.81</StartTime>

    <EndDate>2008-07-08</EndDate>

    <EndTime>06:30:03.83</EndTime>

    <Quantity>3</Quantity>

		<OIDuration>12</OIDuration>

    <OIOrderingLocation>O1410</OIOrderingLocation>

    <GeneratedOIIndicator>433</GeneratedOIIndicator>

	<BillingStatus></BillingStatus>

    <OIReceivingLocation>O1410</OIReceivingLocation>

    <ListPrice>300</ListPrice>

	<ItemPrice>500</ItemPrice>

	<ManualOverridePrice></ManualOverridePrice>

    <DiscountedAmount>0</DiscountedAmount>

    <PharmacyRafflesClassificationCode></PharmacyRafflesClassificationCode>

    <ApptID>A7800</ApptID>

	<ApptDate>2008-07-07</ApptDate>

	<ApptTime>11:15:39.26</ApptTime>

   	<ApptStatus>G983</ApptStatus>

	<ArrivalDate>2008-07-07</ArrivalDate>

	<ArrivalTime>03:54:54.35</ArrivalTime>

    <DepartureDate>2008-07-15</DepartureDate>

    <DepartureTime>03:54:54.35</DepartureTime>

    <CareProvider>Surgeon</CareProvider>

    <CareProviderType>Surgeon</CareProviderType>

    <ServiceRendered></ServiceRendered>

    <ServiceTaxCode>X9990</ServiceTaxCode>

    <OIUrgency>I90</OIUrgency>

    </ORDITEM>

	

	<BILLINFO>

    <BillItemRowId></BillItemRowId>

    <OrderItemCode></OrderItemCode>

    <StartDate></StartDate>

    <StartTime></StartTime>

    <EndDate></EndDate>

    <EndTime></EndTime>

    <Quantity></Quantity>

    <OIDuration></OIDuration>

    <OIOrderingLocation></OIOrderingLocation>

    <GeneratedOIIndicator></GeneratedOIIndicator>

    <ItemUnitPrice></ItemUnitPrice>

    <ManualPriceOverride>0</ManualPriceOverride>

    <OrderItemPayor></OrderItemPayor>

    <OrderItemPayor></OrderItemPayor>

    <OrderItemPayor></OrderItemPayor>

    <OrderItemPlan></OrderItemPlan>

    <OrderItemTotal></OrderItemTotal>

    <OrderItemGST></OrderItemGST>

    <ContractAdjustment></ContractAdjustment>

    <OIErrorMessage></OIErrorMessage>

    <BillingErrorMessage></BillingErrorMessage>

    <BillingDebugMessage></BillingDebugMessage>

    </BILLINFO>

	

</PATIENTBILL>

Open in new window

0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22765378
try adding this to your No example and see if it works.

It seems, adding the property where the suffix "Specified" is added and having it return false if the main property is null should help the serialiser.
        [XmlIgnore]

        public bool NoSpecified

        {

            get

            {

                return no.HasValue;

            }

        }

Open in new window

0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 2

Author Comment

by:tryokane
ID: 22765744
Can u show me how to do this ?
0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22766894
Your XML indicates this is serialisation over several classes each of which has property attributes to customise how the data is serialised.

Non of your examples so far would match this XML and each example is different and therefore may have a different issue.

Could you provide a snipet of the part of the XML and the related property code that is having the problem. Is it a .Net nullable type (?) or not?

Note: the IsNullable="true" option is not related to .Net nullable types.

The previous example I gave is a possible solution to serialising .Net nullable types (?).
0
 
LVL 2

Author Comment

by:tryokane
ID: 22773390
Below is the code sample
 [Serializable]

  public class SegmentEpisode

  {

#region Properties

      [XmlElement(ElementName = "EpisodeId", IsNullable = true)]

    public string Id

    {

      get { return m_Id; }

      set { m_Id = value; }

    }

      [XmlElement(ElementName = "EpisodeNumber", IsNullable = true)]

    public string Number

    {

      get { return m_Number; }

      set { m_Number = value; }

    }

      [XmlElement(ElementName = "EpisodeType", IsNullable = true)]

    public string Type

    {

      get { return m_Type; }

      set { m_Type = value; }

    }

      [XmlElement(ElementName = "EpisodeSubType", IsNullable = true)]

    public string SubType

    {

      get { return m_SubType; }

      set { m_SubType = value; }

    }

      [XmlElement(ElementName = "EpisodeDate")]

    public DateTime Date

    {

      get { return m_Date; }

      set { m_Date = value; }

    }

[XmlElement(ElementName = "DischargeTime")]

    public DateTime DischargeTime

    {

      get { return m_DischargeTime; }

      set { m_DischargeTime = value; }

    }

}

Open in new window

0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22773496
I think I get it.

Is it that you sometimes have this in your xml:

<DischargeTime></DischargeTime>

As DateTime is built in type, and it can't equal null, the serialiser tries to parse an empty string into a DateTime, and bang.

Same problem for any property that is a built in type...int, double

0
 
LVL 2

Author Comment

by:tryokane
ID: 22773774
Yes correct.I am getting for int,decimal and datetime mainly this error when they are null.
0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22774634
It seems the xml you are providing is invalid for the serialiser. If a property is null its element should either be excluded or it should be defined like this:

<DischargeTime xsi:nil="true"></DischargeTime>

If you created the Xml using the serialiser you will notice that it does the above. The property has to be an object or a nullable built in type (see code). If the xsi:nil='true' is missing you will get your error.

I think you will have some trouble using the serialiser like this if you can't give it the exact XML schema it requires. To cope with that XML you may have to write your own IXmlSerializable methods.


        private DateTime? m_DischargeTime;

        [XmlElement(ElementName = "DischargeTime", IsNullable = true)]

        public DateTime? DischargeTime

        {

            get { return m_DischargeTime; }

            set { m_DischargeTime = value; }

        }

Open in new window

0
 
LVL 2

Author Comment

by:tryokane
ID: 22774739
I tried the above method but i am still getting the same error.What is wrong i didnt understand?
0
 
LVL 23

Expert Comment

by:Tiggerito
ID: 22774923
Did you correct you XML so it includes the xsi:nil="true" attributes where the elements are blank?

You will have to do the suggested code for all your system type properties that need to allow null.

As a tip, when you get the exception, you can get more information by looking at its inner exception. You will probably see that you are getting a schema error of some sort.
0
 
LVL 2

Author Comment

by:tryokane
ID: 22784490
Can u show me how to do?Must i do for each element ?
0
 
LVL 23

Accepted Solution

by:
Tiggerito earned 250 total points
ID: 22785239
The first question is. Do you have control over the format of the xml that the serialiser has to parse.

If not, you will have to write a custom parser that can handle the non compliant xml.

If you can. For each blank element in your supplied xml. e.g.

<MyProperty></MyProperty>

You have to indicate it is null. The only exception is string types.

<MyProperty xsi:nil="true"></MyProperty>

Then. You have to make sure all your C# properties will support null values. That is, if they are not naturally nullable (i.e. not class based or a string) they have to be decaired as a nullable type by using a question mark (?) and have the xml IsNullable attribute included.

e.g.
        private Int32? myProperty;

        [XmlElement(ElementName = "MyProperty", IsNullable = true)]

        public Int32? MyProperty

        {

            get { return myProperty; }

            set { myProperty = value; }

        }

Open in new window

0
 
LVL 2

Author Closing Comment

by:tryokane
ID: 31507731
Thanks for your suggestions.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now