This is my sample XML Code:
<bestContact> <firstName><![CDATA[12345]]></firstName> <lastName /> </bestContact>
I am using:
<xs:element name="lastName" type="xs:string" minOccurs="1" nillable="false"/>
The XSD Should be validate lastName
as not null or empty.
In an XML document, the usual way to represent a null value is to leave the element or attribute empty. Some business messages use a special value to represent a null value: <price>-999</price> .
Answers. The proper way with the W3C XML schema language is using nillable="true" in the schema and xsi: nil="true" in the XML instance document e.g.
The nillable attribute can be defined on an xsd:element within an XML schema. It specifies that the xsi:nil attribute is valid for the element. If an XML schema has defined the nillable attribute as true, it is mapped as a required attribute and is included in the document, however, its values are nullified.
Try
<xs:element name="lastName" minOccurs="1" nillable="false"> <xs:simpleType> <xs:restriction base="xs:string"> <xs:minLength value="1"/> </xs:restriction> </xs:simpleType> </xs:element>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With