How can i check if the XML element can or cannot be blank?

Last post 05-11-2008 6:56 AM by jedi_knight. 4 replies.

Sort Posts:

  • How can i check if the XML element can or cannot be blank?

    05-07-2008, 8:14 AM
    • Loading...
    • jedi_knight
    • Joined on 05-07-2008, 8:09 AM
    • Posts 3

    Hi all!

     I have an XML schema and i need to check if the XML element corresponding to the schema type can or cannot be blank. How can i do it?

     I use .NET framework 3.0 and c#.

    Thanks for all answers.

     

  • Re: How can i check if the XML element can or cannot be blank?

    05-07-2008, 8:39 AM
    • Loading...
    • Swati Jain
    • Joined on 05-24-2006, 12:29 PM
    • Pune
    • Posts 687

     Hi

    xsi:nil attribute needs
    to be checked if its true or not.

  • Re: How can i check if the XML element can or cannot be blank?

    05-07-2008, 8:50 AM
    • Loading...
    • jedi_knight
    • Joined on 05-07-2008, 8:09 AM
    • Posts 3

    Thanks!

     But i still have one problem - i've loaded the XML element type info into the XmlSchemaElement and i've checked the  XmlSchemaElement.IsNillable property - the property value was "false".  OK, then i've checked another XML elrment of another XML type and the XmlSchemaElement.IsNillable property also was "false". There are two XML elements description below:

    <xs:element name="TypeCd" type="ClassifierItem" minOccurs="0" maxOccurs="1">

    </xs:element>

    <xs:element name="IssueDate" type="xs:date" minOccurs="0" maxOccurs="1">

    </xs:element>

     No element has xsi:nil attribute and both element types have value "false" of XmlSchemaElement.IsNillable property. BUT! The MS InfoPath shows the "TypeCd" as "can be blank" and "IssueDate" as "cannot be blank". The only difference between two elements is different types. The "TypeCd" according to the custom type "ClassifierItem" defined in the same schema and the "IssueDate" according to the "xs:date" defined in the http://www.w3.org/2001/XMLSchema

     

    I'm still in the problem! How InfoPath can define if the element cannot be blank and why i cannot?

     

  • Re: How can i check if the XML element can or cannot be blank?

    05-08-2008, 10:43 PM

    Hi jedi_knight ,

    jedi_knight:
    I'm still in the problem! How InfoPath can define if the element cannot be blank and why i cannot?

    I think you can do it.

    The <minOccurs> indicator specifies the minimum number of times an element can occur . If you want the element cannot be blank , set it equals 1.

    see here :

    http://www.w3schools.com/schema/schema_complex_indicators.asp

     

    Sincerely,
    Samu Zhang
    Microsoft Online Community Support

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
  • Re: How can i check if the XML element can or cannot be blank?

    05-11-2008, 6:56 AM
    • Loading...
    • jedi_knight
    • Joined on 05-07-2008, 8:09 AM
    • Posts 3

    Thank you for your answer!

     But i think there is not a solution in my case. In present time i use just the same way - when i need to define if the element can or cannot be blank i read the element definition and check the <minOccurs> attribute. But i did observe that MS InfoPath makes something different. In the sample above the both element definitions have the same value of attribute  <minOccurs> and for the "xs:date" element InfoPath says "cannot be blank" and for "ClassifierItem" - "can be".. I just can't understand why?

Page 1 of 1 (5 items)