views:

288

answers:

1

I have a class which is generated from an XML file via the XSD.exe tool. The class I have contains an array with elements.

Until recently, rendering the whole document from a fully instantiated business object was possible, however due to the size, we now need to render the documents array elements to a stream so that we don't run out of memory.

However when you render the array elements you get a different element name in the XML serialization. I tried to create an XMLAttributesOverride but this returned me an error stating that I could not override the XmlElement attributes on this property. I am trying to keep this strongly typed and correllated to my XSD, so if anyone knows how to change the name of the XML elements to their array name +1 answer for you.

+2  A: 

Have you tried using the XmlArray and XmlArrayElement attributes?
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlarrayattribute.aspx
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlarrayitemattribute.aspx

[XmlArrayItem(ElementName="GenericItem", Type = typeof(Item)]
[XmlArrayItem(ElementName="BookItem", Type = typeof(BookItem)] 
[XmlArray]
public Item []Items {...}
Zyphrax
Problem is that the XML schema isn't controlled by me. Therefore I'm trying to avoid editing code in the class if possible.
Spence
Works nicely - thanks.
rotary_engine