473,699 Members | 2,579 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:simpleTyp e name="zipcode"> <xs:restricti on base="xs:string "><xs:patte rn value="\d{5}" /></xs:restriction> </xs:simpleType

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

dataset.WriteXm l() 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 2249
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*******@disc ussions.microso ft.com> wrote in message
news:2D******** *************** ***********@mic rosoft.com...
Howto make datagrid enforce rules of xml schema??

Created xml schema in the designer. Constraints created there using the following:
<xs:simpleTyp e name="zipcode"> <xs:restricti on base="xs:string "><xs:patte rn value="\d{5}" /></xs:restriction> </xs:simpleType>
Datagrid does not enforce this rule, even though dataGrid1_Valid ating() is called.
dataset.WriteXm l() 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 "EmployeesSchem a.xsd"
*************** *************** ***

<?xml version="1.0" encoding="utf-8" ?><xs:schema id="EmployeesSc hema" targetNamespace ="http://tempuri.org/EmployeesSchema .xsd" elementFormDefa ult="qualified
xmlns="http://tempuri.org/EmployeesSchema .xsd" xmlns:mstns="ht tp://tempuri.org/EmployeesSchema .xsd
xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs: simpleType name="ZipCode"> <xs:restricti on base="xs:positi veInteger"><xs: pattern value="\d{5}" /></xs:restriction> </xs:simpleType>< xs:complexType name="Address"> <xs:sequence><x s: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="EmployeeL ist"><xs:comple xType><xs:seque nce><xs:element name="Employee" ><xs:complexTyp e><xs:sequence> <xs:element name="Email" type="xs:string " /><xs:element name="Password" type="xs:string " /><xs:element name="HomeAddre ss" type="Address" /><xs:element name="OtherAddr ess" 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" ?><EmployeeLis t 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_Clic k(object sender, System.EventArg s e

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

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

// Bind the grid to the DataSe
dataGrid1.DataS ource = ds

private void btnDisplaySchem a_Click(object sender, System.EventArg s e

// Call the GetXmlSchema method to display the loaded schem
MessageBox.Show (ds.GetXmlSchem a())
private void btnGetXMLSchema _Click(object sender, System.EventArg s e

// Read the XML Schema into the DataSe
ds.ReadXmlSchem a(@"../../EmployeesSchema .xsd")
private void btnSaveXML_Clic k(object sender, System.EventArg s e

// Write out the data in the grid to a new XML fil
ds.WriteXml(@"N ewXmlFile.xml")
*************** **************c ode 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="EmployeeL ist" msdata:IsDataSe t="true" msdata:EnforceC onstraints="Fal se"

EmployeesSchema .xsd
<xs:element name="EmployeeL ist">

Schema from Dataset:
<xs:element name="EmployeeL ist" msdata:IsDataSe t="true" >
Also the Schema from Dataset and Employees.xsd:
<xs:simpleTyp e name="ZipCode"> <xs:restricti on base="xs:positi veInteger" /></xs:simpleType>

Whilst the EmployeesSchema .xsd is:

<xs:simpleTyp e name="ZipCode"> <xs:restricti on base="xs:positi veInteger"><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*******@disc ussions.microso ft.com> wrote in message
news:2D******** *************** ***********@mic rosoft.com...
Howto make datagrid enforce rules of xml schema??
Created xml schema in the designer. Constraints created there using the following:<xs:simpleTyp e name="zipcode"> <xs:restricti on base="xs:string "><xs:patte rn value="\d{5}" /></xs:restriction> </xs:simpleType>> > Datagrid does not enforce this rule, even though dataGrid1_Valid ating() is
called. dataset.WriteXm l() 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
2847
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 to validate and transform some very large (potentially over 100MB) XML documents. This is related to another question I will post next, but for now, I want to focus on one particular topic. The data in question has particular business rules...
3
1599
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 and makes it difficult or impossible to generate data not conforming to the schema. I have downloaded many XML editors, both free/open-source and evaluation copies of commercial software but so far none of them fits my requirements. Many of...
1
1129
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 and an xml schema for the rules.
5
2740
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 found that it comes down to whether there is a "rules=all" attribute (which gives me just a thin black line). If that attribute is not there, you get a 3D effect. I haven't yet been able to figure out what causes it. Here is the table def that...
0
8615
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
9173
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9033
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...
1
8911
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
8882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7748
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
4375
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...
1
3057
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
2345
muto222
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.