473,890 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Custom DataGridView and Xml Schema Enumerations

Core Question: Is there a better way to dynamically pull the allowed
values of an attribute out of a dataset's schema.

I have an XML file that contains a string element with two attributes,
weight and color. for example,

<keyword color="blue" weight="normal" >And</keyword>

the color and weight attributes are restricted to only certain values
(color to the 16 named colors in HTML; weight to normal, bold or italic
-- the defaults being blue and normal, respectively). for example,

<xs:simpleTyp e name="color">
<xs:restricti on base="xs:string ">
<xs:enumerati on value="aqua"/>
<xs:enumerati on value="black"/>
<xs:enumerati on value="black"/>
<xs:enumerati on value="blue"/>
<xs:enumerati on value="fuchsia"/>
<xs:enumerati on value="gray"/>
<xs:enumerati on value="green"/>
<xs:enumerati on value="lime"/>
<xs:enumerati on value="maroon"/>
<xs:enumerati on value="navy"/>
<xs:enumerati on value="olive"/>
<xs:enumerati on value="purple"/>
<xs:enumerati on value="red"/>
<xs:enumerati on value="silver"/>
<xs:enumerati on value="teal"/>
<xs:enumerati on value="white"/>
<xs:enumerati on value="yellow"/>
</xs:restriction>
</xs:simpleType>

I also have a VS-generated typed DataSet which I use to populate a
DataGridView. since I want to limit the values of these two attributes,
I am using a DataGridViewCom boBoxColor to represent each.

Dim colColor As New DataGridViewCom boBoxColumn()
colColor.Header Text = "Color"
colColor.DataPr opertyName = kwords.keyword. colorColumn.Col umnName

two parts are giving me fits
1) getting the allowed values of each column from the DataSet -- I see
no easy way to extract the schema from the DataSet in memory and have
resorted to reading the schema directly from the file an additional time
-- IS THERE A WAY TO DIRECTLY PULL THE SCHEMA OUT OF A DataSet?

2) the procedure for pulling the allowed values from the enumeration
seems overly complex -- IS THERE A BETTER WAY THAN THIS?

here's working code:
'TODO: this seems awkward -- find a better way
Dim schemaset As New XmlSchemaSet()
schemaset.Add(N othing, My.Application. AssemblyInfo.Di rectoryPath +
"\keywords.xsd" )
Dim schema As XmlSchema
For Each schema In schemaset.Schem as()
Dim schobj As XmlSchemaObject
'iterate through types
For Each schobj In schema.SchemaTy pes.Values

If TypeOf (schobj) Is XmlSchemaSimple Type Then 'simple type

'cast to simple type
Dim simple As XmlSchemaSimple Type = _
CType(schobj, XmlSchemaSimple Type)

If TypeOf (simple.Content ) Is _
XmlSchemaSimple TypeRestriction Then 'has restriction

If (simple.Name = "color") Then 'color attribute

'cast Content to STR
Dim rest As XmlSchemaSimple TypeRestriction = _
CType(simple.Co ntent, _
XmlSchemaSimple TypeRestriction )

'each enum value shows as a facet
For Each facet As XmlSchemaFacet In rest.Facets
'add value to combo box items
colColor.Items. Add(facet.Value )
Next 'facet

ElseIf (simple.Name = "weight") Then 'weight attribute

Dim rest As XmlSchemaSimple TypeRestriction = _
CType(simple.Co ntent, _
XmlSchemaSimple TypeRestriction )

For Each facet As XmlSchemaFacet In rest.Facets
colWeight.Items .Add(facet.Valu e)
Next 'facet

End If 'Color

End If 'simle.Content

End If 'XmlSchemaSimpl eType

Next 'schobj

Next 'schema

Thanks!
---
http://code.box.sk
nemo me impune lacessit

*** Sent via Developersdex http://www.developersdex.com ***
Nov 21 '05 #1
0 1789

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

Similar topics

1
1821
by: Don Adams | last post by:
I don't think what I want to do with maxInclusive is possible, but I thought I'd ask others what they thought. As an example, here is some very simple XML: <birthday_cake> <max_pieces>8</max_pieces> <serving name="Joe"> <pieces>2</pieces> </serving> <serving name="Jane">
1
4425
by: Joyce | last post by:
In my schema I have 2 enumerations, let's say, country description and country code, and I want to use them so I can map each country description to its precise country code (and no other). So far I've seen I can define both keys for description and code, but my XMLs validate even if I choose a wrong pair: Here are my both enumerations (abbreviated) <xs:simpleType name="COUNTRYCODE"> <xs:restriction base="xs:int"> <xs:enumeration...
0
1679
by: Joyce | last post by:
The XML Schema design problem to solve is as follows: We have 2 combo boxes to populate from schema data, let's say: 1. States 2. Cities (and this one gets populated depending on the choice of the state) The event management is no problem, the question is, how do we build our XML Schema (that's going to contain the data for both states and
1
1530
by: Jeff S | last post by:
Hello all, I'm trying to design a schema from which I can generate a typed dataset class. I'm having problems incorporating choice and enumerations in the schema and getting the xml results that I want. In the following example I want the TopElement to contain either a Car element *or* a Truck element, but not both. So I tried to use a Choice tag to accomplish this. However, The Car element is of type CarType which is a simpleType...
2
9655
by: Steve | last post by:
Hi- OK, I've got a DataGridView, I've created a BindingSource from one of my Business Entity object (based on generated classes from EntitySpaces) I've left the default column setup so that all the columns are displayed. My DataSource objects are composed like this: class Customer : esCustomer // where esCustomer is the EntitySpaces class that was generated
15
2168
by: Jeff Mason | last post by:
Hi, I'm having a reflection brain fog here, perhaps someone can set me on the right track. I'd like to define a custom attribute to be used in a class hierarchy. What I want to do is to have an attribute which can be applied to a class definition of a class which inherits from a base, mustinherit class. I want to define methods in the base class which will access the contents of the attribute as it is applied to
2
7826
by: michael sorens | last post by:
I have been trying to figure out how to use DataSets, BindingSources, DataGridViews, and XML together, but it is a challenge. I understand how to populate a DataGridView with XML basically as: DataSet ds = new DataSet(); ds.ReadXml(@"\usr\tmp\sample.xml"); dataGridView.DataSource = ds; dataGridView.DataMember = "targetElement"; What I found through experimentation is that the DataMember may specify
0
3369
by: mk189 | last post by:
Hi, I am trying to create XML schema of custom markup language, enriched by XHTML. In simplified version, the XML documet could look like that: <a:alarm-manual xmlns:a="alarm-manual" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="alarm-manual alarm-manual.xsd" <h:p>Text ... <a:par-value name="myName"/... text </h:p>
3
5635
by: Stewart Berman | last post by:
I have an application that populates a DataGridView control with an XML file: private void Form1_Load(object sender, EventArgs e) { dataGridView1.DataSource = gridDataSet; gridDataSet.ReadXml("E:\\ImageControl.xml"); dataGridView1.DataMember = "Images"; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGridView1.ColumnHeadersVisible = true;...
0
9980
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
9826
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10830
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...
0
9641
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...
1
8018
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
7172
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();...
1
4682
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
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3283
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.