0

I have encountered a situation where I need to exclude a prefix from an element when I serialize the element if I am processing records for a specific year (2016). However, if I am processing records for the previous year (2015), this prefix should be included.

Example:

The 2015 IRS Schema defines the CountryNm and ForeignProvinceNm fields as irs:CountryNm and irs:ForeignProvinceNm as child elements of the ForeignAddressGrpType element.

I have the following defined in a class Address. When I serialize these properties, I get irs:CountryNm and irs:ForeignProvinceNm as expected.

// IRS_Namespace.commonNamespace uses the prefix 'irs'.

[XmlElement(Namespace = IRS_Namespace.commonNamespace)]
public string CountryNm
{
    get { return _CountryName; }
    set { _CountryName = value.Trim(); }
}

[XmlElement(Namespace = IRS_Namespace.commonNamespace)]
public string ForeignProvinceNm
{
    get { return _ForeignProvinceName; }
    set { _ForeignProvinceName = value.Trim(); }
}

If I am interpreting the change documentation for Tax Year 2016 correctly, the IRS updated their Schema definition and removed the prefix from these two fields.

Question:
How can I do that conditionally remove the prefix from these fields when processing TY2016 data vs. TY2015 data?

The IRS has given direction that states sending any TY2015 data must use the 2015 schema, while new records being sent for TY2016, must use the 2016 schema.

Will I need to maintain two (or more, over time) versions of the Address class?

Russ
  • 678
  • 8
  • 26
  • I would think it would be wise to keep two complete versions of the schemas entirely. As in the future pieces could be removed entirely or new fields could be added in. Personally it will lead to cleaner code down the road as things continue to change year after year. – Das Aug 24 '16 at 16:03
  • 1
    @Josh I think you may be right in that it would be easier for me to have an external XML document containing the structure of the XML necessary to be sent for each year (2015 & 2016), rather than depending on the class serialization to output the correct schema. – Russ Aug 24 '16 at 17:03

0 Answers0