1
votes

I have an xml as

<name>
    <l10n lang="en">abc</l10n>
</name>

and the associated xsd for this element is:

<xs:schema elementFormDefault="qualified" targetNamespace="http://iddn.icis.com/ns/core" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:c="http://iddn.icis.com/ns/core" xmlns:conf="http://iddn.icis.com/ns/config" xmlns="http://www.w3.org/1999/xhtml">
<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd">
</xs:import>
 <xs:complexType name="i18n-value">
      <xs:sequence>
         <xs:element name="l10n" maxOccurs="unbounded">
            <xs:complexType>
               <xs:simpleContent>
                  <xs:extension base="xs:string">
                     <xs:attribute ref="lang" use="required"/>
                  </xs:extension>
               </xs:simpleContent>
            </xs:complexType>
         </xs:element>
      </xs:sequence>
   </xs:complexType>

<xs:element name="name" type="c:i18n-value"/>
</xs:schema>

Now I want to add a restriction over the element 'l10n' in a way that its value should not be null and schema validation error should be thrown that is if the input is :

<name>
    <l10n lang="en"></l10n>
</name>

So far I have tried the schema options such as nillable and minOccurs but had no luck. Can someone please suggest me the possible way to resolve this.

Note: Please ignore any missing namespaces in the xsd or xml.

2

2 Answers

1
votes

Actually, what you really want is to add a restriction over the element 'I10n' in a way that its value should not be empty. In XML Schema, a null value is not the same as an empty value. You need to create a simple type that must not be empty. To do that - create a new simple type that is a restriction of xs:string - add a facet minLength="1". - use that simple type as the base type of your complex-type-with-simple-content

For completeness, a null (or more accurately, nil) value in XML is explicitly signalled by adding an attribute xsi:nil="true". When modelling that in XML Schema the equivalent element declaration must have xs:nillable="true", else it will be an error.

The minOccurs attribute specifies the minimum number of occurrences of a tag; it says nothing about the content of a tag.

1
votes

Use the below tags which will cover check for empty,null and empty space

 <xs:simpleType>
    <xs:restriction base="xs:string">
                    <xs:whiteSpace value="collapse"/>
                   <xs:minLength value="1"/>
                 </xs:restriction>
        </xs:simpleType>