473,396 Members | 1,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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:simpleType name="color">
<xs:restriction base="xs:string">
<xs:enumeration value="aqua"/>
<xs:enumeration value="black"/>
<xs:enumeration value="black"/>
<xs:enumeration value="blue"/>
<xs:enumeration value="fuchsia"/>
<xs:enumeration value="gray"/>
<xs:enumeration value="green"/>
<xs:enumeration value="lime"/>
<xs:enumeration value="maroon"/>
<xs:enumeration value="navy"/>
<xs:enumeration value="olive"/>
<xs:enumeration value="purple"/>
<xs:enumeration value="red"/>
<xs:enumeration value="silver"/>
<xs:enumeration value="teal"/>
<xs:enumeration value="white"/>
<xs:enumeration 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 DataGridViewComboBoxColor to represent each.

Dim colColor As New DataGridViewComboBoxColumn()
colColor.HeaderText = "Color"
colColor.DataPropertyName = kwords.keyword.colorColumn.ColumnName

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(Nothing, My.Application.AssemblyInfo.DirectoryPath +
"\keywords.xsd")
Dim schema As XmlSchema
For Each schema In schemaset.Schemas()
Dim schobj As XmlSchemaObject
'iterate through types
For Each schobj In schema.SchemaTypes.Values

If TypeOf (schobj) Is XmlSchemaSimpleType Then 'simple type

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

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

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

'cast Content to STR
Dim rest As XmlSchemaSimpleTypeRestriction = _
CType(simple.Content, _
XmlSchemaSimpleTypeRestriction)

'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 XmlSchemaSimpleTypeRestriction = _
CType(simple.Content, _
XmlSchemaSimpleTypeRestriction)

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

End If 'Color

End If 'simle.Content

End If 'XmlSchemaSimpleType

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 1767

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

Similar topics

1
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>...
1
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...
0
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...
1
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...
2
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...
15
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...
2
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: ...
0
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"...
3
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;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...

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.