locked
nillable attribute in xml schema

    Question

  • Can any one say about nillable attribute in xml schema?  I have requirement of validating an xml schema.  I want to check whether the element's value is empty or not while validating the xml.  While validating it should fail if the specified element's value is empty.

    Thursday, March 20, 2008 7:46 AM

Answers

  • Code Snippet
        <xs:simpleType name="NonEmptyToken">
            <xs:restriction base="xs:token">
                <xs:minLength value="1"/>
            </xs:restriction>
        </xs:simpleType>

     

     

     

    Saturday, March 22, 2008 10:19 PM

All replies

  • I'm sorry, I don't understand your question. Are you asking how to do the validation? Do you need to know how to create an XSD that will be invalid if there is no content in particular places? Simply make the element minOccors="1" and add a minLength facet to the type definition specifying that the minimum length is 1.

     

     

    Thursday, March 20, 2008 12:31 PM
  • Thank you for your answer. You answered my primary question .  I tried to ask this question("Do you need to know how to create an XSD that will be invalid if there is no content in particular places?").    And also I wanted to get clarrified about the nillable attribute.  I refferred W3C pages regarding nillable attributes.  It was bit confusing for me. Could you please explain me about that(nillable attribute in the schema) too?  Please provide me the links which describes about nillable attribute.

     

    I tried to find out minlength.  I could not find that.  How to use minLength faceset?

    Thursday, March 20, 2008 3:37 PM
  • Code Snippet
        <xs:simpleType name="NonEmptyToken">
            <xs:restriction base="xs:token">
                <xs:minLength value="1"/>
            </xs:restriction>
        </xs:simpleType>

     

     

     

    Saturday, March 22, 2008 10:19 PM
  • My requirement got satisfied.  But I am not clear about the nillable attribute.  Can any one explain that?

    Tuesday, March 25, 2008 12:46 PM
  • Nillable means that it's ok for an element that is otherwise required to instead be replaced by

     

    Code Snippet
    <elementName xsi:nil="true"/>

     

     

     

    Tuesday, March 25, 2008 1:14 PM