Log in

View Full Version : How do you AllowNulls when using XML Schema template in Visual Studio?


rocky_raher
07-22-2005, 04:00 PM
I have an application on my PPC which is currently written in Forward Pass (similar to Visual Basic), storing data on a Pocket Access database. I am converting it to C#, using Visual Studio .Net 2003. I will abandon Pocket Access, probably in favor of SQL Server CE, but possibly I'll just save all data as a big XML text file.

I've created the database schema using the XML Schema template, and am importing data from text files dumped from the old application. The problem is that the new schema will not allow nulls in any fields. My data does have a lot of null entries. For now, I'm entering dummy values where the original database had nulls (0 for numeric, 01/01/50 for dates), but this is a rather ugly kludge. The correct way to handle this is to fix the schema, but I'm having zero success at that.

Here's the section of the XML Schema that defines one of my tables:
<xs:element name="Header">
<xs:complexType>
<xs:sequence>
<xs:element name="LastName" type="xs:string" />
<xs:element name="FirstName" type="xs:string" />
<xs:element name="StreetAddress" type="xs:string" />
<xs:element name="CityStateZip" type="xs:string" />
<xs:element name="Rating" type="xs:int" />
<xs:element name="USCF_ID" type="xs:string" />
<xs:element name="Section" type="xs:string" />
<xs:element name="MySide" type="xs:string" />
<xs:element name="MyResult" type="xs:string" />
<xs:element name="GameResult" type="xs:string" />
<xs:element name="Opening" type="xs:string" />
<xs:element name="Variation" type="xs:string" />
<xs:element name="ResultDate" type="xs:date" />
<xs:element name="MyNewRating" type="xs:int" />
<xs:element name="GameNumber" type="xs:int" />
<xs:element name="Commentary" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:key name="HeaderKey1" msdata:PrimaryKey="true">
<xs:selector xpath="." />
<xs:field xpath="mstns:LastName" />
</xs:key>
</xs:element>

I tried modifying the ResultDate field definition like this:
<xs:element name="ResultDate" allownulls="true" type="xs:date" />
but the XML Schema template didn't like it, and I got a runtime error: "The 'alllownulls' attribute is not supported in this context."

Do you have any suggestions about how to make the schema allow nulls?

JonMisurda
07-22-2005, 06:58 PM
http://www.w3schools.com/schema/el_element.asp

shows that the xs:element tag supports a nillable attribute. Maybe that will work?

Jon

rocky_raher
07-22-2005, 08:18 PM
Thank you, JonMisurda!! That worked perfectly!

<xs:element name="ResultDate" nillable="true" type="xs:date" />

I have never heard the term, "nillable," before. Now I notice that it is in the properties list in Visual Studio's schema designer.