Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loading dataset from XML with Schema
Message
From
18/03/2010 10:23:42
 
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454990
Message ID:
01455356
Views:
39
Dmitry,

An empty tag is read as being an empty string. And that's not a boolean value. The tag element has to be totally absent, then the default will kick in.

So, instead of this:
	<field>
		<fld_name>FiscalYear</fld_name>
		<fld_desc>Fiscal Year</fld_desc>
		<fld_type>N</fld_type>
		<fld_len>4</fld_len>
		<def_value>123</def_value>
		<req_entry></req_entry>
	</field>
You would have this:
	<field>
		<fld_name>FiscalYear</fld_name>
		<fld_desc>Fiscal Year</fld_desc>
		<fld_type>N</fld_type>
		<fld_len>4</fld_len>
		<def_value>123</def_value>
	</field>
This will apply to the numeric fields as well. Even strings, although in your case you defaulted a string element to an empty string anyway, so you wouldn't notice the problem there. Maybe it's a bug in DataSet.ReadXml(), but if there's a way around it, I'm not aware of it.

~~Bonnie


>Hi Viv,
>
>Here are the files:
>-- first XSD:
>
>
><?xml version="1.0" encoding="utf-8" ?>
><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
>	<xsd:element name="rules">
>		<xsd:complexType>
>		<xsd:sequence>
>	<xsd:element name="field" minOccurs="0" maxOccurs="unbounded">
>		<xsd:complexType>
>			<xsd:sequence>
>				<xsd:element name="fld_name" type="xsd:string"/>
>				<xsd:element name="fld_desc" type="xsd:string"/>
>				<xsd:element name="fld_type" type="xsd:string"/>
>				<xsd:element name="fld_len" default="0" type="xsd:int"/>
>				<xsd:element name="def_value" default="" type="xsd:string"/>
>				<xsd:element name="req_entry" default="false" type="xsd:boolean"/>				
>			</xsd:sequence>
>		</xsd:complexType>
>	</xsd:element>
>		</xsd:sequence>
>	</xsd:complexType>
></xsd:element>			
></xsd:schema>
>
>
>-- And this is XML:
>
><?xml version="1.0" encoding="utf-8" ?>
><rules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
>	xsi:noNamespaceSchemaLocation="RulesXml.xsd" >
>	<field>
>		<fld_name>ProjectAccount</fld_name>
>		<fld_desc>Project ID/Account Number</fld_desc>
>		<fld_type>C</fld_type>
>		<fld_len>16</fld_len>
>		<def_value></def_value>
>		<req_entry>true</req_entry>
>	</field>
>	<field>
>		<fld_name>FiscalYear</fld_name>
>		<fld_desc>Fiscal Year</fld_desc>
>		<fld_type>N</fld_type>
>		<fld_len>4</fld_len>
>		<def_value>123</def_value>
>		<req_entry>false</req_entry>
>	</field>
></rules>	
>
>
>Note that if I blank the tag "reg_entry" I get error.
>
>Let me know if you see any issues in my XML/XSD.
>
>Thank you.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform