473,327 Members | 2,012 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,327 software developers and data experts.

Datagrid enforcing rules of xml schema?!

Howto make datagrid enforce rules of xml schema?

Created xml schema in the designer. Constraints created there using the following

<xs:simpleType name="zipcode"><xs:restriction base="xs:string"><xs:pattern value="\d{5}" /></xs:restriction></xs:simpleType

Datagrid does not enforce this rule, even though dataGrid1_Validating() is called.

dataset.WriteXml() saves withouth any warning, but

the following dataset.ReadXml() loads with error thrown

I am using the latest 2003 visual studio

Please if there is any working examples of this, or a somewhat extensive error report of dataset and datagrid in particular.

Rgds
O
Nov 16 '05 #1
2 2232
Frosty:

You're declaring/instantiating a strongly typed dataset or applying the
Schema and the grid is allowing it in ? Normally it just kicks out the
value to whatever it was originally if you put in something that violates
the rules. I've never seen this behavior --- can you show me the code that
makes the dataset (or the declaration of the STD) and the code you use to
bind it?
"Frosty" <an*******@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Howto make datagrid enforce rules of xml schema??

Created xml schema in the designer. Constraints created there using the following:
<xs:simpleType name="zipcode"><xs:restriction base="xs:string"><xs:pattern value="\d{5}" /></xs:restriction></xs:simpleType>
Datagrid does not enforce this rule, even though dataGrid1_Validating() is called.
dataset.WriteXml() saves withouth any warning, but

the following dataset.ReadXml() loads with error thrown.

I am using the latest 2003 visual studio.

Please if there is any working examples of this, or a somewhat extensive error report of dataset and datagrid in particular.
Rgds,
OJ

Nov 16 '05 #2
Thanks for your reply William

I have made several attempts and all fails to enforce the constraint. Creating a strongly typed dataset using the designer, then adding (drag and drop) an instance of this dataset to a form together with a datagrid and setting up datagrids datamember and datasource properties in usual manner. No coding required this way, and all works fine except for enforcing the constraints. Have tried various constraints also but to no avail

My example for you follows a different approach. Starting with clean windows application, then adding two items "XML Schema" and "XML File", instead of the usual "Data Set" item, to the application. Then adding a datagrid and a few buttons to the form
*****************************************
***following is the code
*****************************************

***XML Schema, named "EmployeesSchema.xsd"
*********************************

<?xml version="1.0" encoding="utf-8" ?><xs:schema id="EmployeesSchema" targetNamespace="http://tempuri.org/EmployeesSchema.xsd" elementFormDefault="qualified
xmlns="http://tempuri.org/EmployeesSchema.xsd" xmlns:mstns="http://tempuri.org/EmployeesSchema.xsd
xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:simpleType name="ZipCode"><xs:restriction base="xs:positiveInteger"><xs:pattern value="\d{5}" /></xs:restriction></xs:simpleType><xs:complexType name="Address"><xs:sequence><xs:element name="Name" type="xs:string" /><xs:element name="Street" type="xs:string" /><xs:element name="State" type="xs:string" /><xs:element name="Zip" type="ZipCode" /></xs:sequence></xs:complexType><xs:element name="EmployeeList"><xs:complexType><xs:sequence>< xs:element name="Employee"><xs:complexType><xs:sequence><xs:e lement name="Email" type="xs:string" /><xs:element name="Password" type="xs:string" /><xs:element name="HomeAddress" type="Address" /><xs:element name="OtherAddress" type="Address" /></xs:sequence></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element></xs:schema

*************************************
***XML File named "Employees.xml"
***properties for this set to use the EmployeesSchema.xs
*********************************************

<?xml version="1.0" encoding="utf-8" ?><EmployeeList xmlns="http://tempuri.org/EmployeesSchema.xsd"></EmployeeList

************************************************** ***********
***cod
***in addition to defining dataset as part of form and creating in form constructor as usual
***private DataSet ds = new DataSet()
************************************************** ***********

private void btnLoadXML_Click(object sender, System.EventArgs e

// Read the XML Schema into the DataSe
ds.ReadXmlSchema(@"../../EmployeesSchema.xsd")

// Read the XML file into the DataSe
ds.ReadXml(@"../../Employees.xml")

// Bind the grid to the DataSe
dataGrid1.DataSource = ds

private void btnDisplaySchema_Click(object sender, System.EventArgs e

// Call the GetXmlSchema method to display the loaded schem
MessageBox.Show(ds.GetXmlSchema())
private void btnGetXMLSchema_Click(object sender, System.EventArgs e

// Read the XML Schema into the DataSe
ds.ReadXmlSchema(@"../../EmployeesSchema.xsd")
private void btnSaveXML_Click(object sender, System.EventArgs e

// Write out the data in the grid to a new XML fil
ds.WriteXml(@"NewXmlFile.xml")
*****************************code end****************************************

Still constraints are not enforced; ZipCode rejects non integer values as expected but does not enforce the /d{5} constraint.

The Employees.xml have the option of creating a schema file, Employees.xsd. I also added a display schema button that displays the xsd created from the dataset. Using this I have found the following which may indicate cause of error. I would expect the xsd files to be identical as they are all defined from EmployeesSchema.xsd, but they are not

Employees.xsd
<xs:element name="EmployeeList" msdata:IsDataSet="true" msdata:EnforceConstraints="False"

EmployeesSchema.xsd
<xs:element name="EmployeeList">

Schema from Dataset:
<xs:element name="EmployeeList" msdata:IsDataSet="true" >
Also the Schema from Dataset and Employees.xsd:
<xs:simpleType name="ZipCode"><xs:restriction base="xs:positiveInteger" /></xs:simpleType>

Whilst the EmployeesSchema.xsd is:

<xs:simpleType name="ZipCode"><xs:restriction base="xs:positiveInteger"><xs:pattern value="\d{5}" /></xs:restriction></xs:simpleType>

Rgds,
OJ

**********************************


----- William Ryan eMVP wrote: -----

Frosty:

You're declaring/instantiating a strongly typed dataset or applying the
Schema and the grid is allowing it in ? Normally it just kicks out the
value to whatever it was originally if you put in something that violates
the rules. I've never seen this behavior --- can you show me the code that
makes the dataset (or the declaration of the STD) and the code you use to
bind it?
"Frosty" <an*******@discussions.microsoft.com> wrote in message
news:2D**********************************@microsof t.com...
Howto make datagrid enforce rules of xml schema??
Created xml schema in the designer. Constraints created there using the following:<xs:simpleType name="zipcode"><xs:restriction base="xs:string"><xs:pattern value="\d{5}" /></xs:restriction></xs:simpleType>>> Datagrid does not enforce this rule, even though dataGrid1_Validating() is
called. dataset.WriteXml() saves withouth any warning, but
the following dataset.ReadXml() loads with error thrown.
I am using the latest 2003 visual studio.
Please if there is any working examples of this, or a somewhat extensive error report of dataset and datagrid in particular. Rgds,

OJ

Nov 16 '05 #3

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

Similar topics

1
by: Mike | last post by:
Note: My XML experience to date has (unfortunately) been limited to reading and thinking, rather than implementation. Anyway, I am in the process of trying to figure out the most efficient way...
3
by: Xamle Eng | last post by:
I am looking for a data oriented schema-enforcing XML editor. By schema-enforcing I mean an editor that doesn't just have a button to verify the schema - I want an editor that actively enforces it...
1
by: scott | last post by:
Hi all, got a bit of a problem with a datagrid. I have a datagrid that gets it information from a data table which in turn is connected to a data set. The data set is linked to an xml file...
5
by: tshad | last post by:
I have been trying to figure out what the Datagrid is doing to create its formatting. I found that some of my Datagrids have a 3D type of border and sometime it has a straight line. I finally...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.