Fixing errors related to enums

Nov 16, 2009 at 4:48 PM

I'm using xsd2code, latest release,  to deserialise IDMEF messages. I've fixed a couple of errors related to DateTime, which I replaced with string, which is fine, I know they are NTPTimeStamps anyway. But now I'm down to the core problem with the xsd generated class, which is it can't seem to deseralise with compound, or linked enums, element. Here is the xsd2code generated class cutout.

    public partial class UserId : EntityBase<UserId>
    {
        private List<string> itemsField;

        private List<ItemsChoiceType> itemsElementNameField;

        private string identField;

        private idtype typeField;

        private string ttyField;

        public UserId()
        {
            this.identField = "0";
            this.typeField = idtype.originaluser;
        }

        [System.Xml.Serialization.XmlElementAttribute("name", typeof(string))]
        [System.Xml.Serialization.XmlElementAttribute("number", typeof(string), DataType = "integer")]
        [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
        public List<string> Items
        {
            get
            {
                if ((this.itemsField == null))
                {
                    this.itemsField = new List<string>();
                }
                return this.itemsField;
            }
            set
            {
                this.itemsField = value;
            }
        }

        [System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public List<ItemsChoiceType> ItemsElementName
        {
            get
            {
                if ((this.itemsElementNameField == null))
                {
                    this.itemsElementNameField = new List<ItemsChoiceType>();
                }
                return this.itemsElementNameField;
            }
            set
            {
                this.itemsElementNameField = value;
            }
        }

    }

    [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "2.0.50727.4016")]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://iana.org/idmef", IncludeInSchema = false)]
    public enum ItemsChoiceType
    {

        /// <remarks/>
        name,

        /// <remarks/>
        number,
    }

    XML cutout to deserialize.

     <idmef:User ident="0" category="unknown">
                <idmef:UserId tty="String" type="original-user" ident="0">
                       <idmef:name>UserID12</idmef:name>
                        <idmef:number>10</idmef:number>
                </idmef:UserId>
                <idmef:UserId tty="String1" type="original-user" ident="1">
                    <idmef:name>UserID122</idmef:name>
                    <idmef:number>101</idmef:number>
                </idmef:UserId>
                <idmef:UserId tty="String2" type="original-user" ident="2">
                    <idmef:name>UserID123</idmef:name>
                    <idmef:number>102</idmef:number>
                </idmef:UserId>
 </idmef:User>

The problem is that in the you can have multiple items of either name or number from the  ItemsChoiceType enum. So when it deserialises, say for a number 12,  it will have  position 1 of items it will be 12 and at positon 1 of ItemsElementName it will be the enum value number. The deserializable xml is show below. But it is crapping out. There is about 3 or four of these examples within the IDMEF schema, which need changed.

The question is, how would I go about changing the xsd generated classes, so it will deserialize and serialize correctly, as I'm writing as well, and still confirm to the IDMEF schema.

Thanks.

Bob.