Jump to content

Nillable Elements


Recommended Posts

Hi,I am having issues with elements with null values. The elements can be of many different types.Currently I have only be able to do this with a union on simple types, but I also want to allow complex types to be nulls. I have also tinkered with an XSLT that removes blank elements that works but I am after a neater approach.From all the documentation that I have read this is possible with the nillable="true" on the element tag but the program I am using (Liquid XML) say the xml is well formed but is invalid for the xsd. Some background on how the XML is created. A DB processes that is not smart enough to exclude null values in the tables creates the xml document. Where there is a null the tag is created as <exampletag /> and when there is a blank (not null) value the tag is create as exampletag></exampletag>.Can someone please confirm my xsd/xml is valid and the issue is with the program I am using to validate the xml, or tell me what I am doing wrong with my schema?<!-- Schema File mytest.xsd --><?xml version="1.0" encoding="utf-8" ?><xs:schema id="property" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="mydata"> <xs:complexType> <xs:sequence> <xs:element minOccurs="1" maxOccurs="2" name="nulltest" nillable="true"> <xs:simpleType> <xs:restriction base="xs:decimal" /> </xs:simpleType> </xs:element> </xs:sequence> </xs:complexType> </xs:element></xs:schema><!-- XML File mytest.xml--><?xml version="1.0" encoding="utf-8"?><mydata xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mytest.xsd"> <nulltest>1.1</nulltest> <nulltest></nulltest></mydata><!-- Error Message -->The 'nulltest' element is invalid - The value '' is invalid according to its datatype 'Decimal' - The string '' is not a valid Decimal value.Some clarification please!Josh

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...