Jump to content

Useing an Empty Element


Guest bdandr

Recommended Posts

I'm trying to develop an XML document that can contain elements with no data. I ran into an issue where if the element type was integer or double, the XML document would fail validation. The sample schema below is what was used to validate the XML document. XML Document #1 is the one that fails validation and XML Document #2 passes validation.My question is why do I need to include the 'xsi:nil=""' string in the IntegerElement and not in the StringElement? Is there a work around where I don't need to include the 'xsi:nil=""' string in an element?Sample Schema:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">	<xs:element name="TestElement">		<xs:complexType>			<xs:sequence>				<xs:element name="StringElement" type="xs:string" nillable="true"/>				<xs:element name="IntegerElement" type="xs:integer" nillable="true"/>			</xs:sequence>		</xs:complexType>	</xs:element></xs:schema>

Sample XML Document #1: This fails validation due to the element 'IntegerElement' not being valid according to its type definition 'xs:integer'.

<?xml version="1.0" encoding="UTF-8"?><TestElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\testSchema.xsd">	<StringElement></StringElement>	<IntegerElement></IntegerElement></TestElement>

Sample XML Document #2: This passes validation.

<?xml version="1.0" encoding="UTF-8"?><TestElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\testSchema.xsd">	<StringElement></StringElement>	<IntegerElement xsi:nil=""></IntegerElement></TestElement>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...