Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Restricting data

Question posted by: =?Utf-8?B?RG9u?= (Guest) on June 27th, 2008 07:20 PM
Hi

I am trying to put value restrictions on certain elements in an xml file
using a schema file.
The syntax in my schema file looks like the following


<xs:element name="AXYZMachines" msdata:IsDataSet="true"
msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="MotionParameters">
<xs:complexType>
<xs:sequence>
<xs:element name="FeedRateMAX" type="xs:double">
<xs:restriction base="xs:double">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1000"/>
</xs:restriction>
</xs:element>
<xs:element name="PlungeRateMAX" type="xs:string"
minOccurs="0" />
<xs:element name="TravelRateMAX" type="xs:string"
minOccurs="0" />
<xs:element name="TravelRate" type="xs:string" minOccurs="0" />
<xs:element name="PlungeRate" type="xs:string" minOccurs="0" />
<xs:element name="FeedRate" type="xs:string" minOccurs="0" />
<xs:element name="JogSpeedMode" type="xs:string" minOccurs="0"
/>
<xs:element name="SeekXYSpeed" type="xs:string" minOccurs="0" />
<xs:element name="SeekZSpeed" type="xs:string" minOccurs="0" />
<xs:element name="JerkGrate" type="xs:string" minOccurs="0" />
<xs:element name="AccelerationG" type="xs:string"
minOccurs="0" />
<xs:element name="AccelMAX" type="xs:string" minOccurs="0" />
<xs:element name="JerkMAX" type="xs:string" minOccurs="0" />
<xs:element name="CentripetalG" type="xs:string" minOccurs="0"
/>
<xs:element name="BrakeG" type="xs:string" minOccurs="0" />
<xs:element name="ArcError" type="xs:string" minOccurs="0" />
<xs:element name="MinLength" type="xs:string" minOccurs="0" />
<xs:element name="CornerPause" type="xs:string" minOccurs="0" />
<xs:element name="StartPause" type="xs:string" minOccurs="0" />
<xs:element name="JerkFactor" type="xs:string" minOccurs="0" />
<xs:element name="CentripetalAcceleration" type="xs:string"
minOccurs="0" />
<xs:element name="LinearAcceleration" type="xs:string"
minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>

I also have the following C# code that reads the schema in

dsMachineParameters = new DataSet("MachineParameters");
dsMachineParameters.ReadXmlSchema("SchemaA.xsd");

I get the following exception from my C# code:

The 'http/://www.w3.org/2001/XMLSchema:restriction' element is not supported
in this context. How can I add restrictions ranges on values?
--
Don
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
June 27th, 2008
07:20 PM
#2

Re: Restricting data
Don wrote:
Quote:
Originally Posted by
<xs:element name="FeedRateMAX" type="xs:double">
<xs:restriction base="xs:double">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1000"/>
</xs:restriction>
</xs:element>


I think you need
<xs:element name="FeedRateMAX">
<xs:simpleType>
<xs:restriction base="xs:double">


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

=?Utf-8?B?RG9u?='s Avatar
=?Utf-8?B?RG9u?=
Guest
n/a Posts
June 27th, 2008
07:20 PM
#3

Re: Restricting data
I tried the following:
<xs:element name="FeedRateMAX" type="xs:double">
<xs:simpleType>
<xs:restriction base="xs:double">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

and get the following exceptiion:
The type attribute cannot be present with either simpleType or complexType
--
Don


"Martin Honnen" wrote:
Quote:
Originally Posted by
Don wrote:
>
Quote:
Originally Posted by
<xs:element name="FeedRateMAX" type="xs:double">
<xs:restriction base="xs:double">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1000"/>
</xs:restriction>
</xs:element>

>
I think you need
<xs:element name="FeedRateMAX">
<xs:simpleType>
<xs:restriction base="xs:double">
>
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
>


Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
June 27th, 2008
07:20 PM
#4

Re: Restricting data
Don wrote:
Quote:
Originally Posted by
I tried the following:
<xs:element name="FeedRateMAX" type="xs:double">
<xs:simpleType>
<xs:restriction base="xs:double">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
>
and get the following exceptiion:
The type attribute cannot be present with either simpleType or complexType


Well that is not what I suggested, drop the type="xs:double" from the
xs:element.


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

=?Utf-8?B?RG9u?='s Avatar
=?Utf-8?B?RG9u?=
Guest
n/a Posts
June 27th, 2008
07:20 PM
#5

Re: Restricting data
Hi Martin,

Thanks for your input. The exception does not happen anymore but now when I
load the a datagrid using the following

dsMachineParameters = new DataSet("MachineParameters");
mydatagrid = new DataGrid();
mydatagrid.DataSource = dsMachineParameters;
dataGridView1.Controls.Add(mydatagrid);

I am still allowed to change the value to something greater than 1000. This
is not what I expected?

--
Don


"Martin Honnen" wrote:
Quote:
Originally Posted by
Don wrote:
Quote:
Originally Posted by
I tried the following:
<xs:element name="FeedRateMAX" type="xs:double">
<xs:simpleType>
<xs:restriction base="xs:double">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="1000"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

and get the following exceptiion:
The type attribute cannot be present with either simpleType or complexType

>
Well that is not what I suggested, drop the type="xs:double" from the
xs:element.
>
>
--
>
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
>


Martin Honnen's Avatar
Martin Honnen
Guest
n/a Posts
June 27th, 2008
07:20 PM
#6

Re: Restricting data
Don wrote:
Quote:
Originally Posted by
Thanks for your input. The exception does not happen anymore but now when I
load the a datagrid using the following
>
dsMachineParameters = new DataSet("MachineParameters");
mydatagrid = new DataGrid();
mydatagrid.DataSource = dsMachineParameters;
dataGridView1.Controls.Add(mydatagrid);
>
I am still allowed to change the value to something greater than 1000. This
is not what I expected?


I think in terms of the W3C XML schema language you have the right type
definition now. I don't know however whether such restrictions in a
schema are enforced by DataSets or DataGridViews. I did a quick test
here and it indeed looks as if the DataSet does not enforce such
restrictions like minInclusive or maxInclusive. I am not sure how to
change that. You might want to ask in an ADO.NET group.




--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

 
Not the answer you were looking for? Post your question . . .
183,967 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors