I am trying to write a tool for importing ONIX books in C #. I started by creating classes using Xsd2Code and got a huge file with all the properties that, after several settings, do not create any error during deserialization.
I am trying to deserialize an entire element at a time, into a large object in memory, and then do things with it (for example, store it in a database).
The way the Xsd2Code classes are generated, besides the fact that there are many properties, is a bit strange, at least for me.
Here is one of the classes that should be a property of the Product object:
public partial class NotificationType
{
public NotificationTypeRefname refname { get; set; }
public NotificationTypeShortname shortname { get; set; }
public SourceTypeCode sourcetype { get; set; }
public List1 Value { get; set; }
}
I would like to draw your attention to this line:
public List1 Value { get; set; }
"List1" is an enumeration defined as follows:
public enum List1
{
[System.Xml.Serialization.XmlEnum("01")]
Item01,
[System.Xml.Serialization.XmlEnum("02")]
Item02, etc...
, . .
XmlEnum ( "NotificationType" ) ..... !
:
var p = new Product();
XmlSerializer pserializer = new XmlSerializer(p.GetType());
object pDeserialized = pserializer.Deserialize(reader);
p = (Product) pDeserialized;
XML:
<NotificationType>03</NotificationType>
, # Product:
public NotificationType NotificationType { get; set; }
:
public List1 NotificationType { get; set; }
"Item03", , XML. , , "" NotificationType Item01 ( Enum).
SO -, Value (Strings), Enums. - ?
. , . .