Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / May 2008

Tip: Looking for answers? Try searching our database.

Restricting data

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Don - 30 May 2008 14:56 GMT
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?
Signature

Don

Martin Honnen - 30 May 2008 16:08 GMT
>               <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">

Signature

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

Don - 30 May 2008 16:44 GMT
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
Signature

Don

> >               <xs:element name="FeedRateMAX" type="xs:double">
> >             <xs:restriction base="xs:double">
[quoted text clipped - 7 lines]
>      <xs:simpleType>
>        <xs:restriction base="xs:double">
Martin Honnen - 30 May 2008 16:50 GMT
> I tried the following:
>                <xs:element name="FeedRateMAX" type="xs:double">
[quoted text clipped - 8 lines]
> 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.

Signature

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

Don - 30 May 2008 17:16 GMT
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?

Signature

Don

> > I tried the following:
> >                <xs:element name="FeedRateMAX" type="xs:double">
[quoted text clipped - 11 lines]
> Well that is not what I suggested, drop the type="xs:double" from the
> xs:element.
Martin Honnen - 30 May 2008 17:42 GMT
> Thanks for your input.  The exception does not happen anymore but now when I
> load the a datagrid using the following
[quoted text clipped - 6 lines]
> 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.

Signature

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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.