XML Schema for Form Templates

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

XML Schema for Form Templates

bwallis42
Should I be able to validate a form template using the schema xforms-1_0-orbeon.xsd found in src/main/resources/org/orbeon/oxf/xml/schemas?

I've tried loading that schema but it seems to be invalid (I'm using Orbeon 4.9)

For example the attributeGroup XML.Events uses the namespace xs in the definitions of "event", "observer" and "target" but that namespace (ns) is not defined. I think that this namespace should be xsd.

    <xsd:attributeGroup name="XML.Events">
        <xsd:attribute name="iterate" type="xsd:string" use="optional"/>
        <xsd:attribute name="if" type="xsd:string" use="optional"/>
        <xsd:attribute name="while" type="xsd:string" use="optional"/>
        <xsd:attribute name="model" type="xsd:NMTOKEN" use="optional"/>
        <xsd:attribute name="event" type="xs:NMTOKEN"/>
        <xsd:attribute name="observer" type="xs:NMTOKEN"/>
        <xsd:attribute name="target" type="xs:NMTOKEN"/>
        <xsd:attribute ref="ev:event"/>
        <xsd:attribute ref="ev:observer"/>
        <xsd:attribute ref="ev:target"/>
        <xsd:attribute ref="ev:handler"/>
        <xsd:attribute ref="ev:phase"/>
        <xsd:attribute ref="ev:propagate"/>
        <xsd:attribute ref="ev:defaultAction"/>
    </xsd:attributeGroup>

and in a lot of places there are duplicate definitions of attributes, e.g. the rebuild element defines the attribute "model" but that attribute is also declared in the included attribute group XML.Events

<xsd:element name="rebuild">
        <xsd:complexType>
            <xsd:attributeGroup ref="xforms:Common.Attributes"/>
            <xsd:attribute name="model" type="xsd:NMTOKEN" use="optional"/>
            <xsd:attributeGroup ref="xforms:XML.Events"/>
        </xsd:complexType>
    </xsd:element>

and

    <xsd:attributeGroup name="XML.Events">
        <xsd:attribute name="iterate" type="xsd:string" use="optional"/>
        <xsd:attribute name="if" type="xsd:string" use="optional"/>
        <xsd:attribute name="while" type="xsd:string" use="optional"/>
        <xsd:attribute name="model" type="xsd:NMTOKEN" use="optional"/>
        <xsd:attribute name="event" type="xs:NMTOKEN"/>
        <xsd:attribute name="observer" type="xs:NMTOKEN"/>
        <xsd:attribute name="target" type="xs:NMTOKEN"/>
        <xsd:attribute ref="ev:event"/>
        <xsd:attribute ref="ev:observer"/>
        <xsd:attribute ref="ev:target"/>
        <xsd:attribute ref="ev:handler"/>
        <xsd:attribute ref="ev:phase"/>
        <xsd:attribute ref="ev:propagate"/>
        <xsd:attribute ref="ev:defaultAction"/>
    </xsd:attributeGroup>

and in the attributeGroup Nodeset.Binding.Attributes ref is just defined twice:

    <xsd:attributeGroup name="Nodeset.Binding.Attributes">
        <xsd:attribute name="model" type="xsd:NMTOKEN" use="optional"/>
        <!-- XForms 1.2 deprecates @nodeset -->
        <xsd:attribute name="ref" type="xforms:XPathExpression" use="optional"/>
        <xsd:attribute name="nodeset" type="xforms:XPathExpression" use="optional"/>
        <xsd:attribute name="ref" type="xforms:XPathExpression" use="optional"/>
        <xsd:attribute name="bind" type="xsd:NMTOKEN" use="optional"/>
    </xsd:attributeGroup>

In some cases the different declarations of the same attribute have different types, e.g. the attribute "context" in the attributeGroup Common.Attributes is defined an "xsd:string" but in the included attributeGroup Single.Node.Binding.Attributes the attribute "context" is defined as a "xforms:XPathExpression". Both these groups are used in a number of element definitions such as label and hint.

I'm reading the schema with the following code

            InputStream xmlStream = getTemplate(templateVersionId);
            Source      xmlFile   = new StreamSource(xmlStream);

            InputStream schemaStream = this.getClass().getResourceAsStream(baseSchemaFile);

            Source schemaFile = new StreamSource(schemaStream, "http://localhost:8080/cpforbeon4migration/schemas");

            SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
            schemaFactory.setResourceResolver(new LSResourceResolver()
                {
                    @Override
                    public LSInput resolveResource(String type,
                                                   String namespaceURI,
                                                   String publicId,
                                                   String systemId,
                                                   String baseURI)
                    {
                        String resName = systemId.substring(systemId.lastIndexOf("/") + 1);

                        InputStream resStream = this.getClass().getResourceAsStream("/schemas/" + resName);

                        if(resStream == null)
                        {
                            return null;
                        }
                        else
                        {
                            DOMInputImpl ret = new DOMInputImpl(publicId, systemId, baseURI, resStream, null);

                            return ret;
                        }
                    }
                });

            Schema    schema    = schemaFactory.newSchema(schemaFile);

thanks
brian wallis...
Reply | Threaded
Open this post in threaded view
|

Re: XML Schema for Form Templates

Alessandro  Vernet
Administrator
Hi Brian,

Not necessarily: xforms-1_0-orbeon.xsd is intended to be used in XML editors (e.g. IntelliJ) so you can have "some" error highlighting and code completion when editing XForms by hand.

The schema can be used with IntelliJ, but the errors you point to should be fixed. Feel free to send us your changes in a pull request to the project on GitHub.

Alex
--
Follow Orbeon on Twitter: @orbeon
Follow me on Twitter: @avernet