restrictions for attributes

Discussion in 'XML' started by ruthless@poczta.onet.pl, Dec 7, 2003.

  1. Guest

    hello.

    I've got a problem - can I do any restrictions for my attributes?

    I found how to restrict elements and was trying to use them with my
    attributes

    e.g. <person sex="F"> sex can be anly F and M

    i've got sth like this:

    <xs:complexType name="person-type">
    [...]
    <xs:attribute name="sex">
    <xs:restriction base="xs:string">
    <xs:pattern value="F|M"/>
    </xs:restriction>
    </xs:attribute>
    </xs:complexType>

    when I valid it using: http://www.w3.org/2001/03/webdata/xsv i recieve info:

    * The schema(s) used for schema-validation had no errors

    so my scheme is correct or not?
    I recieve errors while i'm validating xml + xsd, xsd itself is valid(see
    above)

    xml is correct i have only change my xsd file with the sex attribute
    without sex restrictions it was OK

    thnx in advance



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.542 / Virus Database: 336 - Release Date: 03-11-18
     
    , Dec 7, 2003
    #1
    1. Advertising

  2. wrote:

    > I've got a problem - can I do any restrictions for my attributes?
    >
    > I found how to restrict elements and was trying to use them with my
    > attributes
    >
    > e.g. <person sex="F"> sex can be anly F and M
    >
    > i've got sth like this:
    >
    > <xs:complexType name="person-type">
    > [...]
    > <xs:attribute name="sex">
    > <xs:restriction base="xs:string">
    > <xs:pattern value="F|M"/>
    > </xs:restriction>
    > </xs:attribute>
    > </xs:complexType>
    >
    > when I valid it using: http://www.w3.org/2001/03/webdata/xsv i recieve info:
    >
    > * The schema(s) used for schema-validation had no errors
    >
    > so my scheme is correct or not?
    > I recieve errors while i'm validating xml + xsd, xsd itself is valid(see
    > above)
    >
    > xml is correct i have only change my xsd file with the sex attribute
    > without sex restrictions it was OK


    You need to restrict a simple type as in

    <xs:element name="root">
    <xs:complexType>
    <xs:attribute name="att" use="required">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:pattern value="yes|no" />
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>
    </xs:element>

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Dec 7, 2003
    #2
    1. Advertising

  3. Guest

    Re: restrictions for attributes - thnx

    thnx - it's working

    greetings R

    Uzytkownik "Martin Honnen" <> napisal w wiadomosci
    news:3fd36c86$...
    >
    >
    > wrote:
    >
    > > I've got a problem - can I do any restrictions for my attributes?
    > >
    > > I found how to restrict elements and was trying to use them with my
    > > attributes
    > >
    > > e.g. <person sex="F"> sex can be anly F and M
    > >
    > > i've got sth like this:
    > >
    > > <xs:complexType name="person-type">
    > > [...]
    > > <xs:attribute name="sex">
    > > <xs:restriction base="xs:string">
    > > <xs:pattern value="F|M"/>
    > > </xs:restriction>
    > > </xs:attribute>
    > > </xs:complexType>
    > >
    > > when I valid it using: http://www.w3.org/2001/03/webdata/xsv i recieve

    info:
    > >
    > > * The schema(s) used for schema-validation had no errors
    > >
    > > so my scheme is correct or not?
    > > I recieve errors while i'm validating xml + xsd, xsd itself is valid(see
    > > above)
    > >
    > > xml is correct i have only change my xsd file with the sex attribute
    > > without sex restrictions it was OK

    >
    > You need to restrict a simple type as in
    >
    > <xs:element name="root">
    > <xs:complexType>
    > <xs:attribute name="att" use="required">
    > <xs:simpleType>
    > <xs:restriction base="xs:string">
    > <xs:pattern value="yes|no" />
    > </xs:restriction>
    > </xs:simpleType>
    > </xs:attribute>
    > </xs:complexType>
    > </xs:element>
    >
    > --
    >
    > Martin Honnen
    > http://JavaScript.FAQTs.com/
    >



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.542 / Virus Database: 336 - Release Date: 03-11-18
     
    , Dec 7, 2003
    #3
  4. Mike Rawlins Guest

    Off the top of my head that ought to work, though there may be something
    wrong in the regular express you use to specify the pattern. However,
    rather than trying to fix your pattern, the more conventional way to do
    what you want is to use the xs:enumeration element for each allowed value.
    --
    Michael C. Rawlins, Rawlins EC Consulting
    www.rawlinsecconsulting.com
    Using XML with Legacy Business Applications (Addison-Wesley, 2003)
     
    Mike Rawlins, Dec 10, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    536
  2. Dan Platton

    character restrictions in names

    Dan Platton, Aug 27, 2003, in forum: Java
    Replies:
    0
    Views:
    304
    Dan Platton
    Aug 27, 2003
  3. poematrix
    Replies:
    2
    Views:
    428
    Martin Honnen
    Sep 7, 2004
  4. Replies:
    4
    Views:
    467
  5. Marc Hebert
    Replies:
    3
    Views:
    633
Loading...

Share This Page