473,385 Members | 1,732 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,385 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 6674
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" />...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.