Restricting data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?RG9u?=

    Restricting data

    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="AXYZMachi nes" msdata:IsDataSe t="true"
    msdata:UseCurre ntLocale="true" >
    <xs:complexType >
    <xs:choice minOccurs="0" maxOccurs="unbo unded">
    <xs:element name="MotionPar ameters">
    <xs:complexType >
    <xs:sequence>
    <xs:element name="FeedRateM AX" type="xs:double ">
    <xs:restricti on base="xs:double ">
    <xs:minInclusiv e value="0"/>
    <xs:maxInclusiv e value="1000"/>
    </xs:restriction>
    </xs:element>
    <xs:element name="PlungeRat eMAX" type="xs:string "
    minOccurs="0" />
    <xs:element name="TravelRat eMAX" type="xs:string "
    minOccurs="0" />
    <xs:element name="TravelRat e" type="xs:string " minOccurs="0" />
    <xs:element name="PlungeRat e" type="xs:string " minOccurs="0" />
    <xs:element name="FeedRate" type="xs:string " minOccurs="0" />
    <xs:element name="JogSpeedM ode" type="xs:string " minOccurs="0"
    />
    <xs:element name="SeekXYSpe ed" type="xs:string " minOccurs="0" />
    <xs:element name="SeekZSpee d" type="xs:string " minOccurs="0" />
    <xs:element name="JerkGrate " type="xs:string " minOccurs="0" />
    <xs:element name="Accelerat ionG" 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="Centripet alG" 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="CornerPau se" type="xs:string " minOccurs="0" />
    <xs:element name="StartPaus e" type="xs:string " minOccurs="0" />
    <xs:element name="JerkFacto r" type="xs:string " minOccurs="0" />
    <xs:element name="Centripet alAcceleration" type="xs:string "
    minOccurs="0" />
    <xs:element name="LinearAcc eleration" type="xs:string "
    minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>

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

    dsMachineParame ters = new DataSet("Machin eParameters");
    dsMachineParame ters.ReadXmlSch ema("SchemaA.xs d");

    I get the following exception from my C# code:

    The 'http/://www.w3.org/2001/XMLSchema:restr iction' element is not supported
    in this context. How can I add restrictions ranges on values?
    --
    Don
  • Martin Honnen

    #2
    Re: Restricting data

    Don wrote:
    <xs:element name="FeedRateM AX" type="xs:double ">
    <xs:restricti on base="xs:double ">
    <xs:minInclusiv e value="0"/>
    <xs:maxInclusiv e value="1000"/>
    </xs:restriction>
    </xs:element>
    I think you need
    <xs:element name="FeedRateM AX">
    <xs:simpleTyp e>
    <xs:restricti on base="xs:double ">


    --

    Martin Honnen --- MVP XML

    Comment

    • =?Utf-8?B?RG9u?=

      #3
      Re: Restricting data

      I tried the following:
      <xs:element name="FeedRateM AX" type="xs:double ">
      <xs:simpleTyp e>
      <xs:restricti on base="xs:double ">
      <xs:minInclusiv e value="0"/>
      <xs:maxInclusiv e 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:
      Don wrote:
      >
      <xs:element name="FeedRateM AX" type="xs:double ">
      <xs:restricti on base="xs:double ">
      <xs:minInclusiv e value="0"/>
      <xs:maxInclusiv e value="1000"/>
      </xs:restriction>
      </xs:element>
      >
      I think you need
      <xs:element name="FeedRateM AX">
      <xs:simpleTyp e>
      <xs:restricti on base="xs:double ">
      >
      >
      --
      >
      Martin Honnen --- MVP XML

      >

      Comment

      • Martin Honnen

        #4
        Re: Restricting data

        Don wrote:
        I tried the following:
        <xs:element name="FeedRateM AX" type="xs:double ">
        <xs:simpleTyp e>
        <xs:restricti on base="xs:double ">
        <xs:minInclusiv e value="0"/>
        <xs:maxInclusiv e 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

        Comment

        • =?Utf-8?B?RG9u?=

          #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

          dsMachineParame ters = new DataSet("Machin eParameters");
          mydatagrid = new DataGrid();
          mydatagrid.Data Source = dsMachineParame ters;
          dataGridView1.C ontrols.Add(myd atagrid);

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

          --
          Don


          "Martin Honnen" wrote:
          Don wrote:
          I tried the following:
          <xs:element name="FeedRateM AX" type="xs:double ">
          <xs:simpleTyp e>
          <xs:restricti on base="xs:double ">
          <xs:minInclusiv e value="0"/>
          <xs:maxInclusiv e 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

          >

          Comment

          • Martin Honnen

            #6
            Re: Restricting data

            Don wrote:
            Thanks for your input. The exception does not happen anymore but now when I
            load the a datagrid using the following
            >
            dsMachineParame ters = new DataSet("Machin eParameters");
            mydatagrid = new DataGrid();
            mydatagrid.Data Source = dsMachineParame ters;
            dataGridView1.C ontrols.Add(myd atagrid);
            >
            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

            Comment

            Working...