This discussion is archived
4 Replies Latest reply: Oct 17, 2012 2:03 AM by vikram(959352) RSS

XML validation against registered XSD

vikram(959352) Newbie
Currently Being Moderated
I have registered XSD into oracle database, while validating xml against this xsd I got stuck with non-mandatory tags.

Below is the tag-XSD structure:

Status field as String:

<xs:element name="Status" nillable="false"> <xs:annotation> <xs:documentation>Values are 'N' or 'E'</xs:documentation>
</xs:annotation>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

idnumber tag field as Integer:

<xs:element name="idnumber" type="xs:int" nillable="false">
<xs:annotation>
<xs:documentation>id value </xs:documentation>
</xs:annotation>
</xs:element>

As status tag is of string type and I have mentioned it as nillable = "False", but even though when I am passing this tag as <status/>, then also its validating xml.... but as i mentioned nillable property as false then it should not validate it ..... please correct me if i m wrong..

In case of idnumber tag it is of int type. In this case <idnumber/> will not work in either case even it is nillable = true or false. Means we cannt pass null values in integer field..... right?

Please suggest me how to make tag of string datatype as not nillable.
Is there any significance of using nillable = "false" in int datatype tag. Means if we want to make it as optional then need to mention it as minoccurs = 0..... is it correct?

Requirement is simple:
Just want to make some tag as optional and some as mandatory, tag can be of integer or string type.

Thanks in advance.....

Edited by: 959352 on 15-Oct-2012 00:45
  • 1. Re: XML validation against registered XSD
    odie_63 Guru
    Currently Being Moderated
    As status tag is of string type and I have mentioned it as nillable = "False", but even though when I am passing this tag as <status/>, then also its validating xml.... but as i mentioned nillable property as false then it should not validate it ..... please correct me if i m wrong..
    The nillable attribute doesn't work that way. It's easy to look that up in any tutorial.

    nillable = "true" means you allow the element to have a NULL content (different from empty string) by specifying an explicit null attribute :
    <Status xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
    nillable = "false" is the default behaviour.

    Please suggest me how to make tag of string datatype as not nillable.
    Is there any significance of using nillable = "false" in int datatype tag. Means if we want to make it as optional then need to mention it as minoccurs = 0..... is it correct?

    Requirement is simple:
    Just want to make some tag as optional and some as mandatory, tag can be of integer or string type.
    You have to be careful about the vocabulary.
    In my mind, an "optional" element means you can omit it entirely in the instance document (minOccurs="0"), whereas an empty element means the start tag and end tag are there but with no content.

    There are multiple ways to allow for empty or non-empty elements.
    e.g. for a non-empty string :
    <xs:minLength value="1"/>
    or, as in your example, if the content is actually constrained to a list of values, use enumerations.

    xs:int datatype doesn't allow empty values (unless you use xsi:nil).
    A possible solution is to build a new type by unioning (xs:union) an xs:int and an empty string type.
  • 2. Re: XML validation against registered XSD
    vikram(959352) Newbie
    Currently Being Moderated
    Many thanks

    Please give me more clarification on nillable attribute.

    I read that nillable = "false" is default behaviour.

    If it is default then why one can leave a tag of string datatype as empty, while at the same time tag of int type will through an error.

    Whether empty tag is being considered as null value or empty string.... ?

    Nillable = "false" and "xsi:nil" is different or same.

    It may be very basic thing, but I am new to XML.

    Thanks in advance for reply......
  • 3. Re: XML validation against registered XSD
    odie_63 Guru
    Currently Being Moderated
    I read that nillable = "false" is default behaviour.

    If it is default then why one can leave a tag of string datatype as empty, while at the same time tag of int type will through an error.
    An empty string is still a valid string.
    An empty integer is not valid.

    Whether empty tag is being considered as null value or empty string.... ?

    Nillable = "false" and "xsi:nil" is different or same.
    - nillable is a declaration in the schema.
    - xsi:nil is used at instance level.

    Setting nillable="false" means you don't allow the usage of xsi:nil="true" attribute in the instance document.
    Consequently, unless additional restrictions are defined, the behaviour is that of the declared datatype : empty string is valid, empty integer is not valid etc.
  • 4. Re: XML validation against registered XSD
    vikram(959352) Newbie
    Currently Being Moderated
    Yipee !!!!
    Now I got clear idea on this.

    Many Thanks.....

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points