Having trouble with key validation

This should cover W3C XML Schema, Relax NG and DTD related problems.
ProfessorK
Posts: 2

Having trouble with key validation

Fri Oct 21, 2016 2:34 am

Why doesn't the second file produce a validation error in Oxygen??

Schema:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xhtml="http://www.w3.org/1999/xhtml"
    elementFormDefault="qualified">
    <xs:import namespace="http://www.w3.org/1999/xhtml"
        schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd"/>
    <xs:import namespace="http://www.w3.org/XML/1998/namespace"
        schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
    <xs:complexType name="StatRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:attribute name="Name" type="xs:string" use="required"/>
                <xs:attribute name="Abbreviation" type="xs:string" use="required"/>
                <xs:attribute name="Cost" type="xs:positiveInteger" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="Xhtml">
        <xs:complexContent>
            <xs:extension base="xhtml:Block">
                <xs:attributeGroup ref="xhtml:attrs"/>
                <xs:attribute name="onload" type="xhtml:Script"/>
                <xs:attribute name="onunload" type="xhtml:Script"/>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="NullElement"> </xs:complexType>

    <xs:complexType name="ModifierRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:all>
                    <xs:element name="Description" type="Xhtml" minOccurs="1"/>
                    <xs:element name="P1Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P2Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P3Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="BasedOnStat" type="xs:string" minOccurs="0"/>
                </xs:all>
                <xs:attribute name="ModifierName" type="xs:string" use="required"/>
                <xs:attribute name="CostFormula" type="xs:string" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>



    <xs:complexType name="EffectRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:all>
                    <xs:element name="Description" type="Xhtml" minOccurs="1"/>
                    <xs:element name="P1Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P2Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P3Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="BasedOnStat" type="NullElement" minOccurs="0"/>
                </xs:all>
                <xs:attribute name="EffectName" type="xs:string" use="required"/>
                <xs:attribute name="CostFormula" type="xs:string" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="CrockRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:all>
                    <xs:element name="Description" type="Xhtml" minOccurs="1"/>
                    <xs:element name="P1Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P2Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P3Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="BasedOnStat" type="xs:string" minOccurs="0"/>
                </xs:all>
                <xs:attribute name="CrockName" type="xs:string" use="required"/>
                <xs:attribute name="CostFormula" type="xs:string" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="PerqRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:all>
                    <xs:element name="Description" type="Xhtml" minOccurs="1"/>
                    <xs:element name="P1Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P2Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="P3Name" type="xs:string" minOccurs="0"/>
                    <xs:element name="BasedOnStat" type="xs:string" minOccurs="0"/>
                </xs:all>
                <xs:attribute name="CrockName" type="xs:string" use="required"/>
                <xs:attribute name="CostFormula" type="xs:string" use="required"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="SimpleComponentRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:all>
                    <xs:element name="Description" type="Xhtml" minOccurs="1"/>
                    <xs:element name="EffectName" type="xs:string" minOccurs="1"/>
                    <xs:element name="P1Value" type="xs:positiveInteger" minOccurs="0"/>
                    <xs:element name="P2Value" type="xs:positiveInteger" minOccurs="0"/>
                    <xs:element name="P3Value" type="xs:positiveInteger" minOccurs="0"/>
                    <xs:element name="BasedOnStat" type="xs:string" minOccurs="0"/>
                </xs:all>
                <xs:attribute name="ComponentName" type="xs:string" use="required"/>

            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="LinkedComponentRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:sequence>
                    <xs:element name="Description" type="Xhtml" minOccurs="1" maxOccurs="1"/>
                    <xs:element name="Component" type="SimpleComponentRecord" minOccurs="1"
                        maxOccurs="unbounded"/>
                </xs:sequence>
                <xs:attribute name="ComponentName" type="xs:string" use="required"/>

            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="FrameComponentRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:sequence>
                    <xs:element name="Description" type="Xhtml" minOccurs="1" maxOccurs="1"/>
                    <xs:element name="Component" type="SimpleComponentRecord" minOccurs="1"
                        maxOccurs="unbounded"/>
                </xs:sequence>
                <xs:attribute name="ComponentName" type="xs:string" use="required"/>
                <xs:attribute name="PowerPoints" type="xs:positiveInteger"/>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>


    <xs:complexType name="ComponentRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:sequence>
                    <xs:element name="Description" type="Xhtml" minOccurs="1"/>
                    <xs:choice>
                        <xs:element name="Simple" type="SimpleComponentRecord"/>
                        <xs:element name="Linked" type="LinkedComponentRecord"/>
                        <xs:element name="Frame" type="FrameComponentRecord"/>
                    </xs:choice>
                </xs:sequence>
                <xs:attribute name="ComponentName" type="xs:string" use="required"/>

            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:complexType name="CharacterStatistic">
        <xs:attribute name="statName" type="xs:string"/>
        <xs:attribute name="initialValue" type="xs:positiveInteger"/>
        <xs:attribute name="currentValue" type="xs:positiveInteger"/>
    </xs:complexType>

    <xs:complexType name="CharacterComponent">
        <xs:attribute name="ComponentName" type="xs:string" use="required"/>
    </xs:complexType>


    <xs:complexType name="CharacterRecord">
        <xs:complexContent>
            <xs:restriction base="xs:anyType">
                <xs:sequence>
                    <xs:element name="Statistics" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="Statistic" type="CharacterStatistic"/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                    <xs:element name="Components" minOccurs="1" maxOccurs="1">
                        <xs:complexType>
                            <xs:sequence>
                                <xs:element name="Component" type="CharacterComponent" minOccurs="0"
                                    maxOccurs="1"/>
                            </xs:sequence>
                        </xs:complexType>
                    </xs:element>
                </xs:sequence>
            </xs:restriction>
        </xs:complexContent>
    </xs:complexType>

    <xs:element name="World">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Rules" minOccurs="1" maxOccurs="1">
                    <xs:complexType>
                        <xs:all>
                            <xs:element name="Statistics">
                                <xs:complexType>
                                    <xs:sequence minOccurs="0" maxOccurs="unbounded">
                                        <xs:element name="Statistic" type="StatRecord"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Effects">
                                <xs:complexType>
                                    <xs:sequence maxOccurs="unbounded" minOccurs="0">
                                        <xs:element name="Effect" type="EffectRecord"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Modifiers">
                                <xs:complexType>
                                    <xs:sequence maxOccurs="unbounded" minOccurs="0">
                                        <xs:element name="Modifier" type="ModifierRecord"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Crocks">
                                <xs:complexType>
                                    <xs:sequence maxOccurs="unbounded" minOccurs="0">
                                        <xs:element name="Crock" type="CrockRecord"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Perqs">
                                <xs:complexType>
                                    <xs:sequence maxOccurs="unbounded" minOccurs="0">
                                        <xs:element name="Perq" type="PerqRecord"/>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                        </xs:all>
                        <xs:attribute ref="xml:base"/>
                    </xs:complexType>
                </xs:element>
                <xs:element id="Components" name="Components" minOccurs="1" maxOccurs="1">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Component" type="ComponentRecord" minOccurs="0"
                                maxOccurs="unbounded"/>
                        </xs:sequence>
                        <xs:attribute ref="xml:base"/>
                    </xs:complexType>
                </xs:element>
                <xs:element id="Characters" name="Characters" minOccurs="1" maxOccurs="1">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Character" type="CharacterRecord"
                                minOccurs="0" maxOccurs="unbounded" />
                        </xs:sequence>
                        <xs:attribute ref="xml:base"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
        <xs:key name="StatKey">
            <xs:selector xpath="World/Rules/Statistics/Statistic"/>
            <xs:field xpath="@Name"/>
        </xs:key>
        <xs:keyref refer="StatKey" name="CharStatKey" >
            <xs:selector xpath="World/Characters/Character/Statistics/Statistic"/>
            <xs:field xpath="@statName"/>
        </xs:keyref>
        <xs:keyref refer="StatKey" name="SinpleBasedOnStatKey">
            <xs:selector xpath="./Compomnents/Component/Simple"/>
            <xs:field xpath="BasedOnStat"/>
        </xs:keyref>
        <xs:keyref refer="StatKey" name="LinkedBasedOnStatKey">
            <xs:selector xpath="World/Compomnents/Component/Linked/Component"/>
            <xs:field xpath="BasedOnStat"/>
        </xs:keyref>
        <xs:keyref refer="StatKey" name="FrameBasedOnStatKey">
            <xs:selector xpath="World/Compomnents/Component/Frame/Component"/>
            <xs:field xpath="BasedOnStat"/>
        </xs:keyref>
       
    </xs:element>

</xs:schema>


And this is the xml file:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<World xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="file:/L:/Documents/RPG/MUTT/MuttMaster/MuttMaster.xsd"
    xmlns:h="http://www.w3.org/1999/xhtml">
    <Rules>
        <Statistics>
            <Statistic Name="Deftness" Abbreviation="DFT" Cost="5"/>
            <Statistic Name="Agility" Abbreviation="AGI" Cost="3"/>
            <Statistic Name="Strength" Abbreviation="STR" Cost="3"/>
            <Statistic Name="Toughness" Abbreviation="TOU" Cost="3"/>
            <Statistic Name="Perception" Abbreviation="PER" Cost="2"/>
            <Statistic Name="Mind" Abbreviation="MND" Cost="2"/>
            <Statistic Name="Presence" Abbreviation="PRE" Cost="1"/>
            <Statistic Name="Beauty" Abbreviation="BTY" Cost="1"/>
            <Statistic Name="Spirtuality" Abbreviation="SPI" Cost="2"/>
            <Statistic Name="Willpower" Abbreviation="WIL" Cost="2"/>
        </Statistics>
        <Effects>
            <Effect EffectName="Area Knowledge" CostFormula="$P1$*0.5">
                <Description>
                    <h:p>Area knowledge is knowledge of a specific area of study. It is more focused
                        and less action-oriented then a skill. </h:p>
                    <h:p>Some effects may require a specific number of points in one or more area
                        knowledge categories. In addition, the judge may, at her option, have the
                        player roll dice against a knowledge area to gain special information.
                    </h:p>
                </Description>
                <P1Name>Points of Knowledge</P1Name>

            </Effect>
            <Effect EffectName="Communication" CostFormula="$P1$*3">
                <Description>
                    <h:p>The communication effect is used to communicate information privately. It
                        can be used to make everything from radios to telepathic
                        communication.</h:p>
                    <h:p>A given component only communicates one sense ( A number of components may
                        be linked to create multi-sensory communication.)</h:p>
                    <h:p>The value of the communication component adds to the user’s base perception
                        value. </h:p>
                </Description>
                <P1Name>Points of Communication</P1Name>

            </Effect>
            <Effect EffectName="Domination" CostFormula="">
                <Description>
                    <h:p>Domination is a special kind of attack used to control the actions of
                        another character it is bought as a Special Attack(usually but not always
                        based on MIND) and generally requires a skill to use.</h:p>
                    <h:p>The result points are used by the target as a DN for resisting a command. </h:p>
                    <h:p>Domination does not pre-suppose telepathy or any other unusual form of
                        communication. Commands must generally be spoken unless the dominator has an
                        alternate communication effect with which to make their desires known. </h:p>
                    <h:p>Like all effects, Domination is an instantaneous effect but can be bought
                        longer with the Duration advantage. </h:p>
                </Description>

            </Effect>
            <Effect EffectName="Effect Drain" CostFormula="$P1$*6+$P2$*3">
                <Description>
                    <h:p>Effect drain is an effect that subtracts from other effects.</h:p>
                    <h:p>The difficulty of a drain is the MP value of the effect being drained (not
                        including any advantages or disadvantages.) The amount drained is equal in
                        MPs to the result points (the amount by which the difficulty is
                        exceed.)</h:p>
                    <h:p>A target of a Effect Drain may actively resist, adding their bonus die to
                        the diffculty number. </h:p>
                    <h:p>Drained MPs come back at a rate of 1 a turn. An effect drain must have a
                        specific targeted effect declared at creation time. </h:p>
                </Description>
                <P1Name>Points of drain</P1Name>
                <P2Name>Extra rounds</P2Name>

            </Effect>
            <Effect EffectName="Environmental Resistance" CostFormula="$P1$*3">
                <Description>
                    <h:p>This effect gives a character the ability to survive in a normally
                        inhospitable environment. </h:p>
                    <h:p>For 3 MP a character can last a time value of 1 (one round) in an extreme
                        environmental condition of a specific type and has +1 TOUGH against attacks
                        based on that environmental condition. </h:p>
                </Description>
                <P1Name>Points of resistance</P1Name>

            </Effect>
            <Effect EffectName="Extra Limb" CostFormula="$P1$*5">
                <Description>
                    <h:p>This effect gives the player an extra limb.</h:p>
                    <h:p>This is considered another “off hand”. The player suffers the same “one on
                        many’ penalty for using this limb as he does for using his normal second.
                        The advantage is that certain maneuvers are just not possible with only 2
                        hands (i.e. firing 2 pistols AND swinging across a ravine at the same time.)
                    </h:p>
                </Description>
                <P1Name>Number of limbs</P1Name>

            </Effect>
            <Effect EffectName="Healing" CostFormula="$P1$*6">
                <Description>
                    <h:p>The healing effect heals damage done to a character according to the result
                        points of the healing attempt read through the combat damage chart. </h:p>
                    <h:p>The "possibility rated" column is used for both ords and possibility rated
                        characters. What would normally be read as damage is instead read as damage
                        removed. </h:p>
                </Description>
                <P1Name>Points of healing</P1Name>

            </Effect>
            <Effect EffectName="Illusion" CostFormula="$P1$*3">
                <Description>
                    <h:p>This effect allows the user to create an illusion that fools a single sense
                        (it may be bought multiple times with the link option to create
                        multi-sensory illusions).</h:p>
                    <h:p>These illusions have no reality and thus can do no damage nor create other
                        physical effects. (To do illusions with real effects, buy the actual effect
                        with the disadvantage can be disbelieved.)</h:p>
                    <h:p>Illusion effects a single target character only unless bought with the area
                        of effect advantage. </h:p>
                </Description>
                <P1Name>Size value</P1Name>

            </Effect>
            <Effect EffectName="Increased Statistic Limit" CostFormula="$P1$*3">
                <Description>
                    <h:p>This effect allows a character to buy an statistic score up higher then the
                        normal minimum.</h:p>
                    <h:p>Its most typical usage is in a racial or world package. (I.e. An ogre in a
                        fantasy world might have a few points of Increased Statistic Limit(STR).
                    </h:p>
                </Description>
                <P1Name>New limit number</P1Name>
                <BasedOnStat/>
            </Effect>
            <Effect EffectName="Perception" CostFormula="3+$P1$*3">
                <Description>
                    <h:p>The perception effect is the opposite in many ways of Communication. Unlike
                        communication what is received is under the control of the receiver rather
                        then the sender. It can be used to create such components as Clairsentience,
                        security systems, or heightened senses. </h:p>
                    <h:p>It can also be used to create a non-normal sense (radar, magic-sense, etc.) </h:p>
                    <h:p>Perception normally has no range and thus requires physical contact. It can
                        however be bought with the ranged advantage. </h:p>
                </Description>
                <P1Name>Pluses to perception</P1Name>
                <P2Name/>
                <P3Name/>

            </Effect>
            <Effect EffectName="Penetration" CostFormula="$P1$*3">
                <Description>
                    <h:p>The penetration effect allows an object to pass through another object. </h:p>
                    <h:p>The difficulty of penetration is the Toughness of the object being
                        penetrated (the “target object”). The total penetration score minus the
                        target object’s toughness results in a value which is read on the value
                        chart as the maximum speed the penetrator can move while penetrating the
                        target object. </h:p>
                </Description>
                <P1Name>Points of penetration</P1Name>

            </Effect>
            <Effect EffectName="Sensory Block" CostFormula="3+($P1$-1)*3+($P2$-1)*5">
                <Description>
                    <h:p>The sensory block effect makes perception more difficult. For every 1 point
                        of sensory blocking, it ups the difficulty level of perception 1 difficulty
                        level. </h:p>
                    <h:p>As a raw effect it hides a single small object (equal to a size of value
                        1). The area of effect advantage can be bought to create darkness clouds and
                        such. </h:p>
                    <h:p>Sensory Block is bought to block a particular sense (eg sight, smell). It
                        can be bought multiple times and linked to create an effect that blocks more
                        then one sense. </h:p>
                </Description>
                <P1Name>Effect points</P1Name>
                <P2Name>Time Value</P2Name>

            </Effect>
            <Effect EffectName="Sensory Shutdown" CostFormula="3+($P1$-1)*3+($P2$-1)*5">
                <Description>
                    <h:p>Sensory Shutdown is like Sensory Block except rather then hiding an object
                        or effecting an area, it effects a targeted character to decrease the
                        effectiveness of their senses. </h:p>
                    <h:p>Sensory shutdown is bought to shut down a particular sense ( eg sight,
                        smell). It can be bought multiple times and linked to create an effect that
                        blocks more then one sense. </h:p>
                </Description>
                <P1Name>Effect points</P1Name>
                <P2Name>Time Value</P2Name>
                <P3Name/>

            </Effect>
            <Effect EffectName="Skill Points" CostFormula="3*$P1$">
                <Description>
                    <h:p>These are skill adds contained in a component. Often this is used to build
                        tools that aid specific skills. </h:p>
                    <h:p>The advantage these points have over stats is that there is no maximum to
                        be bought up. </h:p>
                </Description>
                <P1Name>Skill Adds</P1Name>
            </Effect>
            <Effect EffectName="Stats" CostFormula="($STATCOST$*$P1$)+(($P2$-14)*3)">
                <Description>
                    <h:p>The stats effect provides additional ability points. The base effect
                        provides a plus to an existing ability along with a limit to the total. </h:p>
                    <h:p>A sword for instance is a stats(STR) component with a “mele combat” use
                        skill. </h:p>
                    <h:p>In the case of multiple STAT effects that add to the same stat, stats are
                        applied from lowest limit total to highest. Each Stat may only add as many
                        points as brings the stat up to its limit total. </h:p>
                </Description>
                <P1Name>Stat Adds</P1Name>
                <P2Name>Max Total</P2Name>
                <BasedOnStat/>
            </Effect>
            <Effect EffectName="Stat Transfer" CostFormula="$P1$+$P2$">
                <Description>
                    <h:p>This moves points from one stat or skill to another. The movement is
                        proportional to the cost of the stat. </h:p>
                    <h:p>The AP cost of stat transfer is equal to half of the cost of the points
                        moved. </h:p>
                    <h:p>Stat Transfer normally lasts one round. Each additional round is a +1 MP
                        advantage. </h:p>
                </Description>
                <P1Name>Points Moved</P1Name>
            </Effect>
            <Effect EffectName="Transit" CostFormula="$P1$*3">
                <Description>
                    <h:p>The transit effect moves things through space. </h:p>
                    <h:p>Note that this only moves the entity the effect is bought for. If the
                        entity is intended to convey other entities in movement, such as in a
                        vehicle, the moving entity must buy the appropriate amount of STR to carry
                        the intended load. </h:p>
                </Description>
                <P1Name>Speed Value</P1Name>
            </Effect>

        </Effects>
        <Modifiers/>
        <Crocks/>
        <Perqs/>
    </Rules>
    <Components>
        <Component ComponentName="foo">
            <Description></Description>
            <Simple ComponentName="">
                <Description></Description>
                <EffectName></EffectName>
                <BasedOnStat>foo</BasedOnStat>
            </Simple>
        </Component>
    </Components>
    <Characters/>
</World>


I thought I was restricting the value of BasedOnStat in component to one of the names in Statistics?
adrian
Posts: 2326

Re: Having trouble with key validation

Tue Oct 25, 2016 3:48 pm

Hi,

Your intentions aren't clear. But there are quite a few mistakes in the keyrefs, including spelling errors for some element names ("Compomnents").
Try to validate your schema with Saxon-EE in Oxygen. This validation returns a few warnings that point out mistakes in the schema keyrefs. XPath should refer inner children, not the parent itself ("World").

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XML Schemas”

Who is online

Users browsing this forum: No registered users and 0 guests