You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Yadira Taylor <yt...@Qcorps.com> on 2001/05/24 18:43:49 UTC

Constraints not kicking in

Hello,

I have 2 schema files: components.xsd, input.xsd
Instance file is: input.xml

I have defined a "unique" constraint, and key & keyref constraints in
components.xsd
Constraints not kicking in.
I use xerces v 1.4.0, a SAX parser where I have declared the following:


        xr.setFeature ("http://xml.org/sax/features/validation", true);
        xr.setFeature ("http://xml.org/sax/features/namespaces", true);
        xr.setFeature
("http://apache.org/xml/features/validation/schema", true);
        xr.setFeature
("http://apache.org/xml/features/validation/schema-full-checking",
true);
        xr.setErrorHandler (sc);

where xr: XMLReader, and sc is class that does parsing/validation.

Thanks,
Yadira Taylor

input.xsd

<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd= "http://www.w3.org/2001/XMLSchema"
         targetNamespace = "http://INPUT"
         xmlns:INPUT = "http://INPUT"
         elementFormDefault = "qualified"
         attributeFormDefault = "unqualified">

        <xsd:simpleType name="Name">
            <xsd:restriction base="xsd:string"/>
        </xsd:simpleType>

        <xsd:element name = "InputDirectory" type = "xsd:string"/>
        <xsd:element name = "BackupDirectory" type = "xsd:string"/>
        <xsd:complexType name = "Input">
                <xsd:sequence>
                        <xsd:element name="Name" type ="Name"/>
                </xsd:sequence>
        </xsd:complexType>
        <xsd:complexType name = "File">
                <xsd:complexContent>
                        <xsd:extension base = "INPUT:Input">
                                <xsd:sequence>
                                        <xsd:element ref =
"INPUT:InputDirectory"/>
                                        <xsd:element ref =
"INPUT:BackupDirectory"
minOccurs = "0"/>
                                </xsd:sequence>
                        </xsd:extension>
                </xsd:complexContent>

        </xsd:complexType>
        <xsd:element name = "Input" type = "INPUT:Input"
abstract="true"/>
        <xsd:element name = "File" type = "INPUT:File" substitutionGroup
=
"INPUT:Input"/>
        <xsd:element name = "REF" type="INPUT:Name"/>
</xsd:schema>

components.xsd

<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns = "http://COMPONENTS"
         targetNamespace = "http://COMPONENTS"
         xmlns:INPUT = "http://INPUT"
         xmlns:xsd = "http://www.w3.org/2001/XMLSchema"
         elementFormDefault = "qualified"
         attributeFormDefault = "unqualified">
        <xsd:import namespace = "http://INPUT" schemaLocation =
"input.xsd"/>
        <xsd:element name = "COMPONENTS">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:choice maxOccurs = "unbounded">
                                        <xsd:element ref="INPUT:Input"/>

                                </xsd:choice>
                                <xsd:element ref = "IMPORT"/>
                        </xsd:sequence>
                </xsd:complexType>
                <xsd:unique name = "input1">
                    <xsd:selector xpath="INPUT:Input"/>
                    <xsd:field xpath="Name"/>
                </xsd:unique>
                <xsd:key name="inputKey">
                    <xsd:selector xpath="INPUT:Input"/>
                    <xsd:field xpath="Name"/>
                </xsd:key>
                <xsd:keyref name="inpRefer" refer="inputKey">
                    <xsd:selector xpath="INPUT:REF"/>
                </xsd:keyref>
        </xsd:element>
        <xsd:element name = "IMPORT">
                <xsd:complexType>
                        <xsd:sequence>
                                <xsd:choice maxOccurs = "unbounded">
                                        <xsd:element ref = "INPUT:REF"/>

                                </xsd:choice>
                        </xsd:sequence>
                </xsd:complexType>
        </xsd:element>
</xsd:schema>

input.xml
<?xml version = "1.0" encoding = "UTF-8"?>
<COMPONENTS xmlns = 'http://COMPONENTS'
            xmlns:xsi = 'http://www.w3.org/2001/XMLSchema-instance'
            xmlns:INPUT = 'http://INPUT'
            xsi:schemaLocation = 'http://COMPONENTS components.xsd
                                  http://INPUT input.xsd'>
        <INPUT:File>
                <INPUT:Name>T1</INPUT:Name>
                <INPUT:InputDirectory>incoming</INPUT:InputDirectory>
                <INPUT:BackupDirectory>backup</INPUT:BackupDirectory>
        </INPUT:File>
        <INPUT:File>
                <INPUT:Name>T1</INPUT:Name>
                <INPUT:InputDirectory>incoming</INPUT:InputDirectory>
                <INPUT:BackupDirectory>backup</INPUT:BackupDirectory>
        </INPUT:File>
        <IMPORT>
                <INPUT:REF>T1</INPUT:REF>
                <INPUT:REF>T2</INPUT:REF>
        </IMPORT>
</COMPONENTS>



---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org