Newbie: fixed and not-empty element

Discussion in 'XML' started by monique, Jan 25, 2006.

  1. monique

    monique Guest

    Hi,

    I have an enumeration and I would like to fix the value of an element.

    A thing like this

    <?xml version="1.0"?>
    <test>
    <single-value>aaa</single-value>
    </test>

    with the schema:

    <?xml version="1.0"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="test">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="single-value"
    type="single-value-type" fixed="aaa" maxOccurs="unbounded" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    <xs:simpleType name="single-value-type">
    <xs:restriction base="xs:string">
    <xs:enumeration value="aaa" />
    <xs:enumeration value="bbb" />
    <xs:enumeration value="ccc" />
    </xs:restriction>
    </xs:simpleType>
    </xs:schema>

    the example validates against the schema and so do this:

    <?xml version="1.0"?>
    <test>
    <single-value/>
    <single-value>aaa</single-value>
    </test>

    I don't want an empty single-value.
    What can I do ?


    This example

    <?xml version="1.0"?>
    <test>
    <single-value/>
    <single-value>aaa</single-value>
    <single-value>bbb</single-value>
    <single-value>ccc</single-value>
    </test>

    doesn't validate on bbb and ccc, just as I need.
    I would like to get the same on <single-value/>.

    Thanks in advance,

    Monique
     
    monique, Jan 25, 2006
    #1
    1. Advertising

  2. When an element value is absent, "fixed" acts as "default".

    --
    Stan Kitsis
    Program Manager, XML Technologies
    Microsoft Corporation

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm

    "monique" <> wrote in message
    news:...
    > Hi,
    >
    > I have an enumeration and I would like to fix the value of an element.
    >
    > A thing like this
    >
    > <?xml version="1.0"?>
    > <test>
    > <single-value>aaa</single-value>
    > </test>
    >
    > with the schema:
    >
    > <?xml version="1.0"?>
    > <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    > elementFormDefault="qualified" attributeFormDefault="unqualified">
    >
    > <xs:element name="test">
    > <xs:complexType>
    > <xs:sequence>
    > <xs:element name="single-value"
    > type="single-value-type" fixed="aaa" maxOccurs="unbounded" />
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > <xs:simpleType name="single-value-type">
    > <xs:restriction base="xs:string">
    > <xs:enumeration value="aaa" />
    > <xs:enumeration value="bbb" />
    > <xs:enumeration value="ccc" />
    > </xs:restriction>
    > </xs:simpleType>
    > </xs:schema>
    >
    > the example validates against the schema and so do this:
    >
    > <?xml version="1.0"?>
    > <test>
    > <single-value/>
    > <single-value>aaa</single-value>
    > </test>
    >
    > I don't want an empty single-value.
    > What can I do ?
    >
    >
    > This example
    >
    > <?xml version="1.0"?>
    > <test>
    > <single-value/>
    > <single-value>aaa</single-value>
    > <single-value>bbb</single-value>
    > <single-value>ccc</single-value>
    > </test>
    >
    > doesn't validate on bbb and ccc, just as I need.
    > I would like to get the same on <single-value/>.
    >
    > Thanks in advance,
    >
    > Monique
    >
     
    Stan Kitsis [MSFT], Jan 26, 2006
    #2
    1. Advertising

  3. monique

    George Bina Guest

    You can use a restriction of your type to that single value:

    <xs:element name="single-value" maxOccurs="unbounded">
    <xs:simpleType>
    <xs:restriction base="single-value-type">
    <xs:enumeration value="aaa"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    </xs:sequence>

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com
     
    George Bina, Jan 27, 2006
    #3
  4. monique

    monique Guest

    Thanks! :)
    It works great!

    Bye
     
    monique, Jan 27, 2006
    #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. johnp
    Replies:
    4
    Views:
    3,721
    Toby Inkster
    May 23, 2005
  2. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,066
    Klaus Johannes Rusch
    Jul 16, 2003
  3. Lukas
    Replies:
    3
    Views:
    868
    spiff
    Nov 10, 2005
  4. Tharanga Abeyseela
    Replies:
    0
    Views:
    86
    Tharanga Abeyseela
    Jan 24, 2014
  5. Neil Cerutti
    Replies:
    0
    Views:
    79
    Neil Cerutti
    Jan 24, 2014
Loading...

Share This Page