0

I have xsd Schema, and gml file according to that schema. When all attributes have values (optional and required) makes gml file valid against schema. But when I intentionally delete few optional attributes on some elements, validator says that gml is not valid against schema.

All optional elements have attribute nullable="true".

What's wrong here?

Example:

Part of schema:

<xsd:complexType name="ADM_DrzavaType" final="#all">
    <xsd:complexContent>
        <xsd:extension base="fgu:KatastarskiGeoObjektType">
            <xsd:sequence>
                <xsd:element name="sifra" type="fgu:CL_ADM_Drzava_Sifra"/>
                <xsd:element name="naziv" type="fgu:CL_ADM_Drzava_Naziv"/>
                <xsd:element name="sluzbena_Povrsina" type="xsd:positiveInteger" nillable="true"/>
                <xsd:element name="povrsina" type="xsd:double" nillable="true"/>
                <xsd:element name="geometrija" type="gml:MultiSurfacePropertyType"/>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

Part of "invalid" gml (sluzbena_Povrsina and povrsina are empty):

<fgu:ADM_Drzava gml:id="Drzava-234">
        <fgu:oid>1122115522125</fgu:oid>
        <fgu:transaction_Time gml:id="Drzava-234-1">
            <gml:beginPosition>20140717190255</gml:beginPosition>
            <gml:endPosition>20140717190255</gml:endPosition>
        </fgu:transaction_Time>
        <fgu:valid_Time gml:id="Drzava-234-2">
            <gml:beginPosition>20140717190255</gml:beginPosition>
            <gml:endPosition>20140717190255</gml:endPosition>
        </fgu:valid_Time>
        <fgu:lineage_Parent>1122115522124</fgu:lineage_Parent>
        <fgu:lineage_Child>1122115522127</fgu:lineage_Child>
        <fgu:napomena>asd</fgu:napomena>
        <fgu:greska>false</fgu:greska>
        <fgu:izvor_Geometrije>GNSS</fgu:izvor_Geometrije>
        <fgu:sifra>BiH</fgu:sifra>
        <fgu:naziv>Bosna i Hercegovina</fgu:naziv>
        <fgu:sluzbena_Povrsina></fgu:sluzbena_Povrsina>
        <fgu:povrsina></fgu:povrsina>
        <fgu:geometrija>
    <!-- this element is long to much, so I will omit it. -->
        </fgu:geometrija>
</fgu:ADM_Drzava>

EDIT:

Missing elements in part of the schema are inherited from other Feature (base="fgu:KatastarskiGeoObjektType").

Aleksandar
  • 1,163
  • 22
  • 41

1 Answers1

2

This is a purely XML based answer because it appears you're using a Non-Geography Markup Language (GML) schema. If you had used a GML schema, I'm not sure this answer would apply.

In XML numbers can't be left blank. Both sluzbena_Povrsina (positiveInteger) and povrsina (double) are numbers so therefore the following syntax will always be invalid: <fgu:povrsina></fgu:povrsina> Marking these elements nillable using nillable="true" requires the instance document to explicitly state the element is nill using this syntax: <fgu:povrsina xsi:nill="true" />

Change these lines:

<fgu:sluzbena_Povrsina></fgu:sluzbena_Povrsina>
<fgu:povrsina></fgu:povrsina>

To this:

<fgu:sluzbena_Povrsina xsi:nill="true" />
<fgu:povrsina xsi:nill="true" />

and it should validate.

****** [Other Options] ******

This may or may not be an option but you might consider dropping the nillability and adding minOccurs="0" like this:

<xsd:element name="sluzbena_Povrsina" type="xsd:positiveInteger" minOccurs="0" />

This would allow you to leave the element out of the instance document completely but it's still invalid if the element is present but empty.

Another option might be to assign a default value like this:

<xsd:element name="sluzbena_Povrsina" type="xsd:positiveInteger" default="0" />

Filling in blank entries with zero may not work. Depending on what this number represents, a zero may cause unexpected results.

Note that some types (string for example) do accept empty values.

Jason Enochs
  • 1,436
  • 1
  • 13
  • 20
  • You're using an XML schema to validate a GML instance. I don't know anything about GML but if using an XML schema for validation meets your needs, I believe it's fine. I did some reading and found that if you had used a Geography Markup Language (GML) schema, making something nillable would have been handled differently. If you are interested in reading how it's done using a GML schema, read this post: https://www.seegrid.csiro.au/wiki/AppSchemas/NilValues It shows you 4 different options for leaving out a value when using a GML schema. – Jason Enochs Jul 31 '14 at 03:16
  • Probably stupid question, but how do I use non-GML when working with geometry and referring to gml namespaces, using prefixes and so on? I really don't understand you. I like your answer, and I hope it will help me, but nonGML? – Aleksandar Jul 31 '14 at 07:39