Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XSD

Status
Not open for further replies.

zeert2002

Programmer
Sep 26, 2007
13
US
Hi, can anybody help me with this xsd rule?

I have this rule in my xsd file:

<xs:element name="id" type="xs:long"/>

In my xml file, this is not acceptable because it says '' is not an integer:

<id></id>

Is there a way in to specify a xsd rule to allow empty content? Thanks
 
[1] Since xs:long is simpleType, this case has a slightly fortunate outcome using xs:union to make it.
[tt]
<xs:element name="id" type="voidable_long" />
<xs:simpleType name="voidable_long">
<xs:union memberTypes="xs:long voidType" />
</xs:simpleType>
<xs:simpleType name="voidType">
<xs:restriction base="xs:string">
<xs:length value="0" />
</xs:restriction>
</xs:simpleType>
[/tt]
[2] For general case, you might have to resort to use XMLSchema-instance namespace specifying in the document instance. (Both forms are validated.)
[tt]
<id xmlns:xsi=" xsi:nil="true"></id>
<id xmlns:xsi=" xsi:nil="true" />
[/tt]
In schema document, script nillable to true.
[tt]
<xs:element name="id" type="xs:long" nillable="true" />
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top