Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Loading dataset from XML with Schema
Message
From
19/03/2010 12:17:37
 
 
To
19/03/2010 10:40:53
General information
Forum:
ASP.NET
Category:
XML
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01454990
Message ID:
01455731
Views:
28
>>I understand that making the element optional will, of course, make it legal to omit it. But that wasn't really my point. If the XML language specification states that where a default value is specified for an element then it should be applied to any such empty element then one would expect the XML as posted by Dimitry to work.
>
>Yes, one would expect that ... however, the DataSet.ReadXml() method won't accept an empty element for anything that is not string. It blows up ("" is not a boolean value or similar error message). That's why I said that perhaps it's a DataSet bug. The only way to specify an empty value of a non-string element it is to *not* include the element tag at all (and making it legal by making it optional with the minOccurs="0"). But that's a Catch-22, since that doesn't give you what you want either (see below).
>
>>AFAICS there's also nothing in the XML specs that says that if an optional element is missing then it should be added using the default value - which *is* what is happening. I thought a missing element in XML should represent a null value. So how do you specify a null value for a table field in XML?
>
>No, you've got what's happening backwards. If the element is optional (minOccurs="0"), then the default will *NOT* be used if the element is missing, which *is* what would happen.

Gotcha.

And you're correct, that missing element would then be NULL, not the default. If, however, you specify minOccurs="1" (or leave it out, since I believe that is the default anyway), then the default value *will* be supplied for any missing element tag ... which was my suggestion to begin with. And which makes sense, at least from the standpoint of how a DataSet utilizes the XML.
>
>The only downside to how the DataSet deals with XML is the fact that XML with a missing non-optional element won't Validate against a schema that doesn't have that missing element marked as optional. And because of the way the DataSet works with XML, you can only mark it as optional if you don't want to specify a default ... IOW, you want missing elements to default to NULL, which they will.

OK so the bottom line is that the only way to get a default value into the Dataset is to have minOccurs=1 and omit the element completely which is against XML rules. I guess we'd better leave it there since my head is beginning to hurt (and it doesn't matter to me anyway) :-}

>
>~~Bonnie
>
>
>>
>>In short I don't think the DataSet class is obeying the rules of XML - and in the case of empty elements I can't see *why* it should not do so. But I'm not that knowledgeable about XML (and even less about DataSets :-{ ) - maybe someone can point out where my thinking is wrong ?
>>
>>
>>>>If I remove a 'req_entry' element then the XML will not validate against the schema - ie according to the schema that's not allowed.
>>>>Also, AFAICS from reading the W3c specs the correct behaviour is as I mentioned before:

>>>
>>>I've never tried to validate XML, so I didn't do it in this case, but I suspect that if minOccurs="0" is added to the element in the .XSD, then it should validate just fine when the element is missing from the XML.
>>>
>>><xsd:element name="req_entry" default="false" type="xsd:boolean" minOccurs="0"/>		
>>>
>>>
>>>Sorry that I didn't mention that earlier, but I guess I missed that little tidbit of info. =0(
>>>
>>>~~Bonnie
>>>
>>>
>>>
>>>>Hi,
>>>>That's very odd.
>>>>If I remove a 'req_entry' element then the XML will not validate against the schema - ie according to the schema that's not allowed.
>>>>Also, AFAICS from reading the W3c specs the correct behaviour is as I mentioned before:
>>>>
>>>>{value constraint} establishes a default or fixed value for an element. If default is specified, and if the element being validated is empty, then the canonical form of the supplied constraint value becomes the schema normalized value of the validated element in the ·post-schema-validation infoset (my italics)
>>>>
>>>>Looks to me as if .Net has decided to define its own behaviour as far as the DataSet goes - and I guess I can see the reasoning - being able to omit elements could drastically reduce the XML size. But that still means that, even though the XML might create a valid DataSet if you attempt to pre-validate it against the defined schema it will fail :-{
Previous
Reply
Map
View

Click here to load this message in the networking platform