Help: XML and Schema

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zeny
    New Member
    • Jul 2006
    • 44

    Help: XML and Schema

    Hi everybody! I´m getting the error "The value of the element is invalid - The value '' is invalid according to its datatype 'Integer' " (I´m using Visual Studio 2005). How can a xsd element be either empty (like the empty string "") or an integer ???

    Would be most thankfull for any help!

    Best regards
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    2 possible ways I can think of.

    1. use nil
    a. Change schema to have attribute nillable="true"
    b. In source, add xsi:nil="true" to the empty element.

    2. base this value on an xs:string, and use a pattern.
    Code:
    <xs:simpleType>
    	<xs:restriction base="xs:string">
    		<xs:pattern value="[0-9]*"/>
    	</xs:restriction>
    </xs:simpleType>

    Comment

    • zeny
      New Member
      • Jul 2006
      • 44

      #3
      Originally posted by jkmyoung
      2 possible ways I can think of.

      1. use nil
      a. Change schema to have attribute nillable="true"
      b. In source, add xsi:nil="true" to the empty element.

      2. base this value on an xs:string, and use a pattern.
      Code:
      <xs:simpleType>
      	<xs:restriction base="xs:string">
      		<xs:pattern value="[0-9]*"/>
      	</xs:restriction>
      </xs:simpleType>
      The second case obviously works, but the first one, although it´s perfectly logical, doesnt work! Can anyone tell why???

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        You might have to define the xmlns:xsi namespace in the source as well.

        Comment

        • scissors
          New Member
          • Aug 2007
          • 4

          #5
          Make the type a union between an empty string and xs:integer.

          Comment

          Working...