I created a class out of .xsd. Now I am generating a new xml file and trying to add "Notice" as an element with an attribute of Index="001". I'm trying to get to value XmlEnumAttribute("0001"). This is how my code looks like:
*************************Class******************** *************
public partial class Notice {
private NoticeIndex indexField;
public Notice() {
this.indexField = NoticeIndex.Item0001;
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
[System.ComponentModel.DefaultValueAttribute(
NoticeIndex.Item0001)]
public NoticeIndex Index {
get {
return this.indexField;
}
set {
this.indexField = value;
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xs d", "2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(Anonymou sType=true)]
public enum NoticeIndex {
/// <remarks/>
[System.Xml.Serialization.XmlEnumAttribute("0001")]
Item0001,
}
*************************End Class*********************************
I saw another post here and tried this from my program but it complains about converting Index to string:
***************************Program**************** ******************
Notice notice = new Notice();
Type enumType = typeof(NoticeIndex);
foreach (System.Reflection.FieldInfo fi in enumType.GetFields())
{
object[] attrs = fi.GetCustomAttributes(typeof(XmlEnumAttribute), false);
if (attrs.Length > 0)
{
bSNShipNotice.Index = ((XmlEnumAttribute)attrs[0]).Name;
}
}
xml.Element.Notice = notice;
************************************************** *******************
Any help would be greatly appreciated.