nick-knowles / NeTEx-XML

Netex XML Schema
Other
10 stars 6 forks source link

Internal reference validation #6

Open skinkie opened 8 years ago

skinkie commented 8 years ago

One of the things that currently seem to lack in the xml schema is the validation of the semantics of a NeTEx document. What I mean here is that a certain object types may refer to another (strict) object type which should fail in the XSD validation, when incorrect. An example of such reference can be found below.

The PointProjectionRef refers to a RoutePoint, there isn't any logic that nameOfRefClass would limit the reference made from this entity to the foreign entity. One would expect that the nameOfRefClass should be defined in the scope of this object. Hence a PointProjectionRef must only refer to object of class of Point. xs:keyref should facilitate this effort. http://docstore.mik.ua/orelly/xml/schema/ch09_03.htm

Secondary the reference itself is not to be present in the document and/or to be unique. If we consider the parent type of all ObjectIds we end up with an xsd:normalizedString. This would lead to the use of xs:ID upon definition and xs:IDREF upon reference. http://docstore.mik.ua/orelly/xml/schema/ch09_01.htm

The XML Source.

<PointProjectionRef nameOfRefClass="RoutePoint" ref="NDOV:RP:NL:Q:36002156"/>

And the XML Schema's:

    <xsd:simpleType name="PointProjectionIdType">
        <xsd:annotation>
            <xsd:documentation>Type for identifier of a POINT PROJECTION.</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="ProjectionIdType"/>
    </xsd:simpleType>
    <xsd:element name="PointProjectionRef" type="PointProjectionRefStructure" substitutionGroup="ProjectionRef">
        <xsd:annotation>
            <xsd:documentation>Reference to a PROJECTION.</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:complexType name="PointProjectionRefStructure">
        <xsd:annotation>
            <xsd:documentation>Type for a reference to a POINT PROJECTION.</xsd:documentation>
        </xsd:annotation>
        <xsd:simpleContent>
            <xsd:restriction base="ProjectionRefStructure">
                <xsd:attribute name="ref" type="PointProjectionIdType" use="required">
                    <xsd:annotation>
                        <xsd:documentation>Identifier of a POINT PROJECTION.</xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
            </xsd:restriction>
        </xsd:simpleContent>
    </xsd:complexType>
    <xsd:element name="VersionOfObjectRef" type="VersionOfObjectRefStructure">
        <xsd:annotation>
            <xsd:documentation>Reference to a NeTEx Object .  i.e. concrete instance of an ENTITY  may include a version. Implements a one to one relationship by reference.</xsd:documentation>
        </xsd:annotation>
    </xsd:element>
    <xsd:complexType name="VersionOfObjectRefStructure">
        <xsd:annotation>
            <xsd:documentation>Type for a versioned reference to a NeTEx Object.</xsd:documentation>
        </xsd:annotation>
        <xsd:simpleContent>
            <xsd:extension base="ObjectIdType">
                <xsd:attribute name="nameOfRefClass" type="NameOfClass" use="optional">
                    <xsd:annotation>
                        <xsd:documentation>Name of Class of the referenced entity. Allows reflection. Fixed for each entity type.</xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
                <xsd:attributeGroup ref="ReferenceModificationDetailsGroup"/>
                <xsd:attribute name="ref" type="ObjectIdType" use="required">
                    <xsd:annotation>
                        <xsd:documentation>Identifier of referenced entity.</xsd:documentation>
                    </xsd:annotation>
                </xsd:attribute>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
    <xsd:simpleType name="ObjectIdType">
        <xsd:annotation>
            <xsd:documentation>Abstract Type for identifier of a NeTEx Object.</xsd:documentation>
        </xsd:annotation>
        <xsd:restriction base="xsd:normalizedString"/>
    </xsd:simpleType>
Aurige commented 8 years ago

NeTEx has a special trick (through the use of the version attribute that you can set to "any" if the version is unknow, undefined or the latest) to activate the vlaidation process. Alle the rules are at the end of the NeTEx_publication.xsd file. You can also define specific rules for external references as wa have done for the French profile (check http://www.normes-donnees-tc.org/wp-content/uploads/2015/10/Validation_NeTEx_Arr%C3%AAt_2015-v2.3.pdf in 4.1-Référence interne, externe et validation automatique, and http://www.normes-donnees-tc.org/wp-content/uploads/2015/11/NF_Profil-NeTEx-%C3%A9l%C3%A9ments-communsF-v1.5-v.pdf in 6.3.1-Codification des identifiants ... sorry it is in French)

skinkie commented 7 years ago

For the Dutch schema I have implemented reference validation. For example:

                <xsd:key name="LineId">
                    <xsd:selector xpath=".//netex:Line"/>
                    <xsd:field xpath="@id"/>
                </xsd:key>
                <xsd:keyref name="LineRef" refer="LineId">
                    <xsd:selector xpath=".//netex:LineRef"/>
                    <xsd:field xpath="@ref"/>
                </xsd:keyref>
skinkie commented 7 years ago

StartPointRef/EndPointRef are not being checked.