473,698 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
+ 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:simpleTyp e>
<xs:restictio n base="xs:string ">
<xs:enumerati on value="value and space 1"/>
<xs:enumerati on 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.Serializat ion.XmlEnumAttr ibute) 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 3665
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.Collecti ons;

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

public xmlEnumAttribut es(Type enumType)
{
if (!enumType.IsEn um)
{
throw new ArgumentExcepti on("Not enumerable type.");
}

foreach (System.Reflect ion.MemberInfo info in enumType.GetMem bers())
{
// I think we can safely assume only one XmlEnumAttribut e per enum value
foreach (System.Xml.Ser ialization.XmlE numAttribute att in
info.GetCustomA ttributes(typeo f(System.Xml.Se rialization.Xml EnumAttribute),
true))
{
_abbrevs.Add(in fo.Name);
_values.Add(att .Name);
break;
}
}
}

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

// example of using the class:
// if myXmlDeserialis edObject.enumer ableValue is of myEnum type

xmlEnumAttribut es myEnumValues = new xmlEnumAttribut es(typeof(myEnu m));
string value = myEnumValues.Ge tValue(myXmlDes erialisedObject .enumerableValu e);

// ***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:simpleTyp e>
<xs:restictio n base="xs:string ">
<xs:enumerati on value="value and space 1"/>
<xs:enumerati on 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.Serializat ion.XmlEnumAttr ibute) 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
3760
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
6507
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" encoding="UTF-8" ?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
0
1056
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
3726
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 table (DEPTH_FROM in TABLE_1) and find the closest matching values from another field in another table (DEPTH_AT in TABLE_2) - the higher matching value and the lower matching value. TABLE_1
3
2541
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"> <xs:enumeration value="Mon"/> <xs:enumeration value="Tue"/> <xs:enumeration value="Wed"/>
0
500
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
914
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 CHRMT1(I) RMT1(J) Area1(K) CHRMT2(S) RMT2(T) Area2(U) 1 | 0.1 | 100 | 1 | 0.4 | 3 1 | 0.5 | 110 | ...
5
2363
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 frm_Check with only two fields SNO and Relation using mainTable. now when i enter values in SNO and in Relation field and after i exit from relation field i want to run an event which should check for SNO and Relation field values in the...
8
2133
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 "-" like this: 5-10-15-20-21-23. these roll numbers are then stored into a mysql database in the same format. now there are all 50 students which are stored in a different table. i just want to match these roll numbers who are absent against all 50...
0
8674
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...
1
8893
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
7723
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
5860
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
4366
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...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
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
2328
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2001
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.