473,289 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Error using derived simpleType as attribute in XSD -> DataSet

I have been given a schema, instances of which I'm required to be able to
consume and generate. I'd like to be able to manipulate these instances as
DataSets internally in my application. The schema defines the following
simpleType:

<xs:simpleType name="cs">
<xs:restriction base="xs:token">
<xs:pattern value="[^\s]*"/>
</xs:restriction>
</xs:simpleType>

If I'm reading that correctly, it's not that different from a normal
xs:token - it simply imposes the extra restriction that the token contain no
whitespace whatsoever. (The normal xs:token permits single internal white
spaces.)

This works if I use it as the type of an element like so:

<xs:element name="BrokenDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:sequence>
<xs:element name="foo" type="cs"/>
</xs:sequence>
</xs:complexType>
</xs:element>

The DataSet generator is quite happy to deal with this. However, this 'cs'
type is often used in a less direct way. For example, it is often used
either directly, or through derivation (xs:restriction) as an attribute in a
complex type. This causes an error (whether using it as a derived type or
using it directly.) For example this:

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="BrokenDataSet"
targetNamespace="http://tempuri.org/BrokenDataSet.xsd"
elementFormDefault="qualified"
attributeFormDefault="qualified"
xmlns="http://tempuri.org/BrokenDataSet.xsd"
xmlns:mstns="http://tempuri.org/BrokenDataSet.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">

<xs:simpleType name="cs">
<xs:restriction base="xs:token">
<xs:pattern value="[^\s]*"/>
</xs:restriction>
</xs:simpleType>

<xs:complexType name="bar">
<xs:attribute name="spong" type="cs"/>
</xs:complexType>

<xs:element name="BrokenDataSet" msdata:IsDataSet="true">
<xs:complexType>
<xs:sequence>
<xs:element name="foo" type="bar"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
results in the following from XSD.EXE:

Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 1.1.4322.573]
Copyright (C) Microsoft Corporation 1998-2002. All rights reserved.

Error: There was an error processing 'BrokenDataSet.xsd'.
- Undefined data type: 'token'.

The error message suggests that something has gone wrong somewhere with
namespaces - 'token' is a standard XSD type, so the fact that XSD.EXE is
barfing on it would typically be indicative of something being wrong
somewhere with the use of namespace declarations. This is why I've included
the entire file above - I'm pretty sure it's all correct. (And XML Spy is
happy with it - it's just XSD.EXE /dataset that doesn't like it.)

Interestingly, if I change from xs:token to xs:string as the base type:

<xs:simpleType name="cs">
<xs:restriction base="xs:string">
<xs:pattern value="[^\s]*"/>
</xs:restriction>
</xs:simpleType>

the error goes away. So it looks like this is specifically something to do
with 'token'. (Rather than being a namespace problem as you might initially
guess from the error message.)

Unfortunately, changing the definition of this 'cs' simpletype to the above
doesn't work in another case that crops up frequently. The schema I have to
work with frequently derives new simpleTypes from the 'cs' type above. For
example, here's a simplified example. (The real thing has more enumeration
items, but this simple version illustrates the problem.)

<xs:simpleType name="cs_NullFlavor">
<xs:restriction base="cs">
<xs:enumeration value="NI" />
<xs:enumeration value="NINF" />
</xs:restriction>
</xs:simpleType>

If we use this as an attribute type by changing the definition of 'bar' in
the earlier example:

<xs:complexType name="bar">
<xs:attribute name="spong" type="cs_NullFlavor"/>
</xs:complexType>

I now get this error out of XSD.EXE:

Error: There was an error processing 'BrokenDataSet.xsd'.
- Undefined data type: 'cs'.

when I try to use the 'bar' type. (Note that this is using the modified
version of 'cs' above - the one which does work if it is used directly as a
attribute type. This 'fixed' version turns out to be broken in derivation
scenarios like this.)

Changing every simple type that derives from 'cs' and making it derive
directly from 'xs:string' instead gets rid of the errors, but requires
non-trivial changes of the content (and meaning) of the schemas. This is
undesirable since I don't own the schemas - it means I'm now working with a
schema definition that is different from my client's. That's risky, and also
a pain when they come up with new or updated schemas.

Is there a better way to work around this problem?
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/
Nov 12 '05 #1
2 6661
Hi Ian,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you cannot generate a DataSet class
with a complex data type in schema. If there is any misunderstanding,
please feel free to let me know.

Based on my research, this is not supported in current .NET framework. It
seems that we cannot use a derived type as type for a certain column in
typed DataSet schema.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 12 '05 #2
Thanks for the reply. Yes, you've understood the problem correctly - thanks
for confirming that I definitely can't do what I was trying to do.

When I wrote my earlier post, I was hoping to be able to convince the
DataSet to read the XML files I need to process directly. But for a number
of reasons (including the limitation you describe here) the schemas I have
to deal with are ones the DataSet can't cope with. (I've since discovered
that in some places, the schemas I'm dealing with would require a many to
many relation. So as I understand it, that's another reason I can't use the
DataSet to deal with them.)

So I've ended up adding an XSLT layer to map between the incoming XML
documents and the DataSet's XML representation. This works around the
requirement to use any particular type in the DataSet's schema - since I'm
now mapping from one schema to another, this gives me the freedom to use
types the DataSet is happy with.
--
Ian Griffiths - http://www.interact-sw.co.uk/iangblog/
DevelopMentor - http://www.develop.com/

"Kevin Yu [MSFT]" wrote:
Hi Ian,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you cannot generate a DataSet class
with a complex data type in schema. If there is any misunderstanding,
please feel free to let me know.

Based on my research, this is not supported in current .NET framework. It
seems that we cannot use a derived type as type for a certain column in
typed DataSet schema.

HTH.

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Lénaïc Huard | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello, I've some namespace problems when defining default values for attributes. My problem seems to come from the fact that the attributes are...
4
by: matt hegarty | last post by:
Hi I am relatively new to XML, but am having problems with a validation issue. When the XML is parsed and validated using Xerces, the following error is seen: cvc-complex-type.3.2.2:...
1
by: brendang | last post by:
Hi, I am getting the following errors on the schema (on the 'Fund_to' and 'Account_to' elements) in Visual Studio.NET when I try to validate the schema itself. I would greatly apreciate any help...
0
by: Jeff | last post by:
This is one that has been stumping me for a few days now. I have an xml document that is based on a schema, and that schema is based on another schema. When using XMLSpy 2004 Enterprise Edition,...
3
by: Mike P | last post by:
I have an xml doucument that I want to validate with a XSD schema. I'm new to this and I don't know exactly how I make the references at the top of the documents so that the XSD file will validate...
5
by: Brice Prunier | last post by:
Here under 4 schemas i'm working with ( it may be long: sorry...) The context is the following : Resident.xsd imports Person.xsd and includes Common.xsd ( anonimous schema: no TargetNamespace )...
3
by: sachinvyas | last post by:
Hi, I have following schema saved in new.xsd <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="http://www.smpte-ra.org/schemas/429.7/2006/CPL"...
13
by: ScottM | last post by:
I have run into a problem generating the class file via the WSDL utility. I have a WSDL file that was generated by XMLSpy and is able to be read by the Java code utility, but I get the following...
1
by: Ben | last post by:
Hi All, I have 2 XSDs - one with the Types to be used throughout the application, and one specific to my module (a.xsd & b.xsd) a.xsd has <xs:attribute name="MyTest"> <xs:simpleType>...
3
by: Kai Schlamp | last post by:
Hello! In my schema I have the following: <xs:complexType name="textareaType"> <xs:simpleContent> <xs:restriction base="xs:string"> <xs:attribute ref="label" use="required" />...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.