473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Matching xsd:enumeration values with spaces in classes

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"/>
...
</xs:restiction>
</xs:simpleType>
<xs:element>

..Net 2003 xsd.exe utility generates a corresponding enumeration without any
spaces (all commas, full stops, etc. are also removed). Now I need to match
the value of the element with one stored in my reference table in the
database, but because the value that comes from the generated class has all
non-alphanumeric characters removed - I am unable to match it.

I noticed that every enumerated value has a custom
(Xml.Serialization.XmlEnumAttribute) attribute assigned to it with the actual
spelling that appears in the document. But I do not know how to retrieve this
attribute from the enumerated value I receive from the class.

Any help is really appreciated.
Nov 12 '05 #1
1 3640
I think I found a solution:

The following code allows to convert .Net abbreviated enumerable values into
their original format. Hope this will help someone.

// *** code start ***
using System;
using System.Collections;

public class xmlEnumAttributes
{
private ArrayList _abbrevs = new ArrayList();
private ArrayList _values = new ArrayList();

public xmlEnumAttributes(Type enumType)
{
if (!enumType.IsEnum)
{
throw new ArgumentException("Not enumerable type.");
}

foreach (System.Reflection.MemberInfo info in enumType.GetMembers())
{
// I think we can safely assume only one XmlEnumAttribute per enum value
foreach (System.Xml.Serialization.XmlEnumAttribute att in
info.GetCustomAttributes(typeof(System.Xml.Seriali zation.XmlEnumAttribute),
true))
{
_abbrevs.Add(info.Name);
_values.Add(att.Name);
break;
}
}
}

public string GetValue(object abbrevValue)
{
string abbrev = abbrevValue.ToString();
int index = _abbrevs.IndexOf(_abbrevs, abbrev);
return (index > -1) ? _values[index] : null;
}
}

// example of using the class:
// if myXmlDeserialisedObject.enumerableValue is of myEnum type

xmlEnumAttributes myEnumValues = new xmlEnumAttributes(typeof(myEnum));
string value = myEnumValues.GetValue(myXmlDeserialisedObject.enum erableValue);

// ***end of code segment ***

PS I have only used string enumerated values and therefore the code for
other enumerated types may require different code. Also If anyone could
specify a better solution to the problem in my original post, I would really
appreciate that.
"Sergey Poberezovskiy" wrote:
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"/>
...
</xs:restiction>
</xs:simpleType>
<xs:element>

.Net 2003 xsd.exe utility generates a corresponding enumeration without any
spaces (all commas, full stops, etc. are also removed). Now I need to match
the value of the element with one stored in my reference table in the
database, but because the value that comes from the generated class has all
non-alphanumeric characters removed - I am unable to match it.

I noticed that every enumerated value has a custom
(Xml.Serialization.XmlEnumAttribute) attribute assigned to it with the actual
spelling that appears in the document. But I do not know how to retrieve this
attribute from the enumerated value I receive from the class.

Any help is really appreciated.

Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Robb Meade | last post by:
Hi all, Ok, lets say I have the following, Request.Form collection which produces this (as the element names) a b c d
8
by: aevans1108 | last post by:
Greetings I can't seem to inherit enumerated values from a globally defined type in my XML schema. XmlSchema.Compile() doesn't like it. Here's the schema. <?xml version="1.0"...
0
by: JamesSmithMz | last post by:
Hi, I'm new in XSD. So I like to enforce the creating of the XML-file. The XML-Strukture would be linke this: <types> <type name="x"/> <type name="y"/> <type name="z"/> </types> <elements>
2
by: Hennie | last post by:
I apologise if this is a stupid question, but I would appreciated any help on this subject. I want to create a view (VIEW_1 in example below) where I take numeric values from a field in one...
3
by: Davidoff | last post by:
Hi, I parse an XML file with a XSD schema. One XmlNode has an attribute whose type is a restriction of xs:string : <xs:simpleType name="stypeDay"> <xs:restriction base="xs:string">...
0
by: news.emn.fr | last post by:
Hello, i got this attribute <xs:attribute name="jour"> <xs:simpleType> <xs:restriction base="stypeJour"> </xs:restriction> </xs:simpleType> </xs:attribute>
0
by: niewczli | last post by:
Hello I am new to VBA and I am having trouble with the program I want to develop. My project involves looking at two data sets in different columns and rows and comparing them. For example...
5
by: mfaisalwarraich | last post by:
Hi, I have a table called mainTable. two fields of this table are SNO which is text and Relation which is also text. there are more than 10 fields in this table. i made a small form called...
8
by: mfaisalwarraich | last post by:
hello, im trying to make an attendance record. im using a form where im entering two values, 1. Date 2. Absent Students im entering roll numbers of the absent students separated by "-"...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
1
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...
0
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...
0
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,...
0
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...
0
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.