Context
I have to map data of my own application to a format of a third party to be able to push this data (drop .xml file on FTP server). I have been given XSD files (which have circular references and don't allow me to generate any .cs files) and some XML examples. In these XML examples I see a construction that is clearly meant to reference objects and thus reuse data in that way. See the following 2 lines as a snippet from the full example:
<Keyword Code="Discovery" ID="keyword_136" />
<Keyword Ref="keyword_136" />
Full example: https://filebin.net/3imdjmvxdj37o4ku/Exemple_CatalogueXFT.xml?t=n2qtmi7d
Current situation
My application is written in .NET and thus I have made DTO's to match the XML example / XSD specifications. These DTO's are then serialized using an XmlWriter.
I have create the following example of these "referenced items -> AttributeItem" and then the "list items that reference the AttributeItem --> ListItem". The output comes close to the XML example of the third party, however some XML attributes are there when they shouldn't be.
Construction and serialization
var catalogueTest = new CatalogueRefTest();
XmlWriter.SerializeToXml(catalogueTest, pathTest);
Class and constructor with dummy data
public class RefItemBase
{
[XmlAttribute("Ref")]
public string Ref { get; set; }
}
public class AttributeItem : RefItemBase
{
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlAttribute("ID")]
public string Id { get; set; }
}
public class ListItem
{
[XmlArray("Attribute")] //SerializeToRefItem
public List<RefItemBase> Attributes { get; set; }
}
public class CatalogueRefTest
{
public CatalogueRefTest()
{
this.Attributes = new List<AttributeItem>();
for (int i = 0; i < 5; i++)
{
var uniqueRef = $"attribute_{i}";
this.Attributes.Add(new AttributeItem
{
Id = uniqueRef,
Ref = uniqueRef,
Name = $"Attribute with name {i}"
});
}
this.ListItems = new List<ListItem>()
{
new ListItem
{
Attributes = this.Attributes.GetRange(0,3).Cast<RefItemBase>().ToList()
},
new ListItem
{
Attributes = this.Attributes.GetRange(1,3).Cast<RefItemBase>().ToList()
}
};
}
[XmlArray("Attribute")] //SerializeToListDefinition
public List<AttributeItem> Attributes { get; set; }
[XmlArray("ListItem")]
public List<ListItem> ListItems { get; set; }
}
Current output
<?xml version="1.0" encoding="utf-8"?>
<CatalogueRefTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Attribute>
<AttributeItem Ref="attribute_0" Name="Attribute with name 0" ID="attribute_0" />
<AttributeItem Ref="attribute_1" Name="Attribute with name 1" ID="attribute_1" />
<AttributeItem Ref="attribute_2" Name="Attribute with name 2" ID="attribute_2" />
<AttributeItem Ref="attribute_3" Name="Attribute with name 3" ID="attribute_3" />
<AttributeItem Ref="attribute_4" Name="Attribute with name 4" ID="attribute_4" />
</Attribute>
<ListItem>
<ListItem>
<Attribute>
<RefItemBase xsi:type="AttributeItem" Ref="attribute_0" Name="Attribute with name 0" ID="attribute_0" />
<RefItemBase xsi:type="AttributeItem" Ref="attribute_1" Name="Attribute with name 1" ID="attribute_1" />
<RefItemBase xsi:type="AttributeItem" Ref="attribute_2" Name="Attribute with name 2" ID="attribute_2" />
</Attribute>
</ListItem>
<ListItem>
<Attribute>
<RefItemBase xsi:type="AttributeItem" Ref="attribute_1" Name="Attribute with name 1" ID="attribute_1" />
<RefItemBase xsi:type="AttributeItem" Ref="attribute_2" Name="Attribute with name 2" ID="attribute_2" />
<RefItemBase xsi:type="AttributeItem" Ref="attribute_3" Name="Attribute with name 3" ID="attribute_3" />
</Attribute>
</ListItem>
</ListItem>
</CatalogueRefTest>
Questions
Am I missing something very obvious with this Ref / ID construction? The casing also makes me think this is in some way "custom" and that the third party knows how to read this but it is not any default serialization.
With the above code / examples. How can I omit the "Ref" attribute for the "reference list" and omit the "Code" / "ID" attributes for the "actual list"?