Jump to content

XML Schema Dynamic MaxOccurs conditioned by another element


Recommended Posts

That I am working on?:

I am generating an XML schema that controls the inclusion of a logical expression in a program.
- Unary (now only work with not) (force MaxOccurss=1 of LOGIC_VALUES)
- Binary (and,or) (force MaxOccurss=Unbounded of LOGIC_VALUES)
You can see the visual schema of code:
Current code, which does not have the requested functionality
<?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified">

    <xs:element name="LOGIC_EXPRESSION">
                <xs:element name="LOGIC_OPERATOR" type="TYPE_LOGIC_OPERATOR"/>
                <xs:element ref="LOGIC_VALUES"/>

    <xs:element name="LOGIC_VALUES">
                <xs:element name="LOGIC_VALUE" minOccurs="1" maxOccurs="unbounded"/>

    <xs:simpleType name="TYPE_LOGIC_OPERATOR">
        <xs:restriction base="xs:string">
            <xs:enumeration value="and"/>
            <xs:enumeration value="or"/>
            <xs:enumeration value="not"/>

What do I need?
I need know:
- If possible in the restriction of logic operator you can force the maxOccur of Logic_Values (dynamic change of maxoccurs to other element)
- If it is possible to do, what should I use?
Example of what I want
You are writting the next XML code:
   <?xml version="1.0" encoding="UTF-8"?>
    <LOGIC_EXPRESSION xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="file:/media/sf_Downloads/xml/Beta.xsd">
The XML schema should detect that it is a unary operator and you should receive an error.
Thaks a million
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...