0

I'm connecting to the soap service in my project. The reference file generated gives me the following xml result, but these xsi: nil = "true" fields, if they are empty, I want to completely remove them. Is it possible?

<SELECT_INVENTORY_PART>
  <PART_NO>151-040860304-0002</PART_NO>
  <DESCRIPTION xsi:nil="true" />
  <CONTRACT xsi:nil="true" />
  <PLANNER_BUYER xsi:nil="true" />
  <CATCH_UNIT_MEAS xsi:nil="true" />
  <INPUT_UNIT_MEAS_GROUP_ID xsi:nil="true" />
  <PRIME_COMMODITY xsi:nil="true" />
  <SECOND_COMMODITY xsi:nil="true" />
  <ASSET_CLASS xsi:nil="true" />
  <PART_STATUS xsi:nil="true" />
  <ABC_CLASS xsi:nil="true" />
  <FREQUENCY_CLASS_DB xsi:nil="true" />
  <LIFECYCLE_STAGE_DB xsi:nil="true" />
  <ACCOUNTING_GROUP xsi:nil="true" />
  <PART_PRODUCT_CODE xsi:nil="true" />
  <PART_PRODUCT_FAMILY xsi:nil="true" />
  <TYPE_DESIGNATION xsi:nil="true" />
</SELECT_INVENTORY_PART>
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]
public string DESCRIPTION
{
    get
    {
        return this.dESCRIPTIONField;
    }
    set
    {
        this.dESCRIPTIONField = value;
    }
}
Olivier Jacot-Descombes
  • 104,806
  • 13
  • 138
  • 188
zafer k
  • 43
  • 1
  • 6
  • 1
    You can't. They are part of the class structure and are need when they are not null. If you never want these values then remove from the class. – jdweng Nov 27 '20 at 10:40
  • `xsi:nil="true"` is present because you set [`XmlElementAttribute.IsNullable = true`](https://learn.microsoft.com/en-us/dotnet/api/system.xml.serialization.xmlelementattribute.isnullable?view=net-5.0): *Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to null as an empty tag with the `xsi:nil` attribute set to `true`.* So remove that and the null values should not get serialized. – dbc Nov 28 '20 at 00:40
  • This may be a duplicate of [Remove xml element with xsi:nil=“true” C# serialization](https://stackoverflow.com/a/52322410/3744182), agree? – dbc Dec 01 '20 at 13:56

0 Answers0