473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I read values from XmlEnumAttribut e values of an Enum

2 New Member
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 XmlEnumAttribut e("0001"). This is how my code looks like:
*************** **********Class *************** *************** ***
public partial class Notice {

private NoticeIndex indexField;

public Notice() {
this.indexField = NoticeIndex.Ite m0001;
}

/// <remarks/>
[System.Xml.Seri alization.XmlAt tributeAttribut e()]
[System.Componen tModel.DefaultV alueAttribute(
NoticeIndex.Ite m0001)]
public NoticeIndex Index {
get {
return this.indexField ;
}
set {
this.indexField = value;
}
}

/// <remarks/>
[System.CodeDom. Compiler.Genera tedCodeAttribut e("xsd", "2.0.50727.1432 ")]
[System.Serializ ableAttribute()]
[System.Xml.Seri alization.XmlTy peAttribute(Ano nymousType=true )]
public enum NoticeIndex {

/// <remarks/>
[System.Xml.Seri alization.XmlEn umAttribute("00 01")]
Item0001,
}
*************** **********End Class********** *************** ********
I saw another post here and tried this from my program but it complains about converting Index to string:
*************** ************Pro gram*********** *************** ********
Notice notice = new Notice();
Type enumType = typeof(NoticeIn dex);
foreach (System.Reflect ion.FieldInfo fi in enumType.GetFie lds())
{
object[] attrs = fi.GetCustomAtt ributes(typeof( XmlEnumAttribut e), false);
if (attrs.Length > 0)
{
bSNShipNotice.I ndex = ((XmlEnumAttrib ute)attrs[0]).Name;
}
}

xml.Element.Not ice = notice;
*************** *************** *************** *************** *********
Any help would be greatly appreciated.
Jan 9 '09 #1
2 6937
vekipeki
229 Recognized Expert New Member
If I understood what you're asking, your problem is that your Index property does not get serialized. The problem is that XmlSerializer does not serialize properties when their value is equal to their default value.

To resolve this, you can comment out the "DefaultVal ue" attributes for your properties:

Expand|Select|Wrap|Line Numbers
  1. // [System.ComponentModel.DefaultValueAttribute(NoticeIndex.Item0001)]
  2.  
If xsd is generating your class at build time (on every build), you can also remove the 'default' attribute from your Notice element xsd schema to avoid getting the DefaultValueAtt ribute in code, but if you cannot change the schema and need to have it updated on every build, consider adding an additional build script to comment out those lines for you (at Perl or batch file, or even a small C# console app, just to be sure that you don't forget it).
Jan 12 '09 #2
fahad77
2 New Member
Thanks for the help vekipeki, it actually works after I comment out the default attribute value and i'm not generating a class out of xsd on a runtime, its just one time thing so I guess i will be okay.
Jan 14 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
43076
by: Gavin | last post by:
Hi, I'm a newbie to programming of any kind. I have posted this to other groups in a hope to get a response from anyone. Can any one tell me how to make my VB program read the Bios serial number (or would HDD be better, or both?) and put that info into VB prog so the program won't work on another computer. My program uses an MSAccess table. Much appreciated if you can help! Thanks
1
3669
by: Sergey Poberezovskiy | last post by:
Hi, I have a simple enumeration in my schema: <xs:element name="el_1"> <xs:simpleType> <xs:restiction base="xs:string"> <xs:enumeration value="value and space 1"/> <xs:enumeration value="value2 with spaces"/> ...
31
3617
by: Michael C | last post by:
If a class inherits from another class, say Form inherits from control, then I can assign the Form to a variable of type Control without needing an explicit conversion, eg Form1 f = new Form1(); Control c = f; An enum value inherits from int but it doesn't get implicitly converted: HorizontalAlignment h = HorizontalAlignment.Center;
3
15106
by: giant food | last post by:
This seems like a long shot, but I wondered if there's a way to loop over the values in an Enum. For example, say I have an Enum as follows: Public Enum statusValues Ready Running Finished Error End Enum
6
4914
by: cipher | last post by:
I have some constant values in my web service that my client application will require. Having to keep server side and client side definitions insync is tedious. I am trying to do something like this: public __value enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 }; However, the resulting wsdl omits the actual flag values: - <s:simpleType name="Colors">
27
2678
by: Ben Finney | last post by:
Antoon Pardon wrote: > I just downloaded your enum module for python > and played a bit with it. IMO some of the behaviour makes it less > usefull. Feedback is appreciated. I'm hoping to provide a "one obvious way" to do enumerations in Python. > >>> from enum import Enum > >>> day = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')
5
6634
by: Edward Clements | last post by:
I have an enum defined as public enum velocityUom { /// <remarks/> ms, /// <remarks/> cma, ...
0
1612
by: Edward Clements | last post by:
This post is a followup to the thread "retrieving the XmlEnumAttribute values for an Enum" in this same forum earlier this month, since my last query in that thread went unanswered. I have an enum defined (DotNet v2) as public enum velocityUom { ms = 21,
0
1103
by: Bum | last post by:
Hello all, I have a C dll I need to tap into and some C code to interpret to vb.net 2005, but am so far unsuccessful. I just get the generic "runtime has encountered a fatal error at XXXXXX memory". I think my prob is passing the variables. Also, I know the * refers to pointers, but not sure how to interpret them. Hope someone can help... 'Here is the C Code: enum XXXXStatus {StatusUnknown = 0, Processed, ...
0
10449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10217
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10168
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4114
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.