473,804 Members | 3,462 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 6938
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
43081
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
3623
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
15110
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
2682
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
6635
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
1104
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
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10343
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
10331
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
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6861
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
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4306
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
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
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.