xsd.exe : Warning message : cannot generate classes

xsd.exe : Warning message : cannot generate classes

Post by Past » Sat, 10 May 2003 22:35:10



Hi
 I have have written a simple schema that I want to be automaticaly
converted into c# classe (UserIdentifier class)using xsd.exe. Here is
the Schema :

<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema targetNamespace="urn:common" xmlns="urn:common"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">

        <xsd:complexType name="UserIdentifier">
                <xsd:simpleContent>
                        <xsd:extension base="xsd:string">
                                <xsd:attribute name="type" type="UserTypeOfIdentifier"
use="required" />
                        </xsd:extension>
                </xsd:simpleContent>
        </xsd:complexType>

        <xsd:simpleType name="UserTypeOfIdentifier">
                <xsd:restriction base="xsd:string">
                        <xsd:enumeration value="PhoneNumber" />
                        <xsd:enumeration value="OpaqueIdentifier" />
                        <xsd:enumeration value="SubscriberIdentifier" />
                        <xsd:enumeration value="TransactionContextIdentifier" />
                        <xsd:enumeration value="Framework" />
                </xsd:restriction>
        </xsd:simpleType>
</xsd:schema>

here is the message that I get when I use "xsd.exe /c
UserIdentifierTypes.xsd"

Warning: cannot generate classes because no top-level elements with
complex type were found.

Question :

How Can I Fix this ?

Is my schema correct (it looks fine in Visual Studio IDE...)?

Is it compatible with xsd.exe ?

Should I write this schema an other way ?

Are there some restrictons with wsdl.exe and xsd.exe regarding
specific elements like "xsd:simpleContent" or instructions lile
"xsd:instructions" ?

Thanks very much for your help.

Best regards,Nicolas.

 
 
 

xsd.exe : Warning message : cannot generate classes

Post by Christoph Schittko [MVP » Sat, 10 May 2003 23:04:43


The XML type system almost like the type system of an OO programming
language. It separates type definitions (classes) and instances of these
types (objects). Your schema only contains type definitions, but no
instances of these types, which in XML Schema are element definitions. Since
the tool generates classes only for type instances you need to add element
definitions to the schema, for example add a line:

<xs:element name="Identifier" type="UserIdentifier" />

and run it again through the xsd tool. You will see a class Identifier with
the structure of the UserIdentifier complexType.

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor


Quote:> Hi
>  I have have written a simple schema that I want to be automaticaly
> converted into c# classe (UserIdentifier class)using xsd.exe. Here is
> the Schema :

> <?xml version="1.0" encoding="utf-8" ?>
> <xsd:schema targetNamespace="urn:common" xmlns="urn:common"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">

> <xsd:complexType name="UserIdentifier">
> <xsd:simpleContent>
> <xsd:extension base="xsd:string">
> <xsd:attribute name="type" type="UserTypeOfIdentifier"
> use="required" />
> </xsd:extension>
> </xsd:simpleContent>
> </xsd:complexType>

> <xsd:simpleType name="UserTypeOfIdentifier">
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="PhoneNumber" />
> <xsd:enumeration value="OpaqueIdentifier" />
> <xsd:enumeration value="SubscriberIdentifier" />
> <xsd:enumeration value="TransactionContextIdentifier" />
> <xsd:enumeration value="Framework" />
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:schema>

> here is the message that I get when I use "xsd.exe /c
> UserIdentifierTypes.xsd"

> Warning: cannot generate classes because no top-level elements with
> complex type were found.

> Question :

> How Can I Fix this ?

> Is my schema correct (it looks fine in Visual Studio IDE...)?

> Is it compatible with xsd.exe ?

> Should I write this schema an other way ?

> Are there some restrictons with wsdl.exe and xsd.exe regarding
> specific elements like "xsd:simpleContent" or instructions lile
> "xsd:instructions" ?

> Thanks very much for your help.

> Best regards,Nicolas.


 
 
 

1. Why: Derivation by Restriction generates XSD.exe warning

Is it illegal to derive-by-restriction from a complex-type that has a
max-length restricted string member?
I have a complex-type (Address_t) that has an optional child element
('theAddressString').  I wish to derive a new complex type
(EnteredAddress_t)that restricts the child element (theAddressString) to be
mandatory.  The child element (theAddressString) is itself restricted to 50
max chars.

When I run the XSD tool to generate serialization classes for the XSD, I get
the following warning:
-------------------------
X:\Phoenix\XML Samples>xsd derivation_test.xsd /c
Microsoft (R) Xml Schemas/DataTypes support utility
[Microsoft (R) .NET Framework, Version 1.0.3705.0]
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.

Schema validation warning: Invalid particle derivation by restriction. An
error occurred at file:///X:/Phoenix/XML Samples/derivation_test.xsd(22, 3).

Warning: Schema could not be validated. Class generation may fail or may
produce incorrect results.

Writing file 'X:\Phoenix\XML Samples\derivation_test.cs'.
-------------------
Here's the smallest schema I could make that would generate the warning:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xs:element name="Address">
  <xs:complexType>
    <xs:choice>
      <xs:element name="aPossibleAddress" type="Address_t"/>
      <xs:element name="aRealAddress" type="EnteredAddress_t"/>
    </xs:choice>
  </xs:complexType>
</xs:element>
<xs:complexType name="Address_t">
  <xs:all>
    <xs:element name="theAddressString" minOccurs="0">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:maxLength value="50"/>
      </xs:restriction>
    </xs:simpleType>
    </xs:element>
  </xs:all>
</xs:complexType>
  <xs:complexType name="EnteredAddress_t">
  <xs:complexContent>
  <xs:restriction base="Address_t">
    <xs:all>
      <xs:element name="theAddressString">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:maxLength value="50"/>
          </xs:restriction>
      </xs:simpleType>
      </xs:element>
    </xs:all>
  </xs:restriction>
</xs:complexContent>
</xs:complexType>
</xs:schema>

Thanks in advance for reading this far, and for any suggestions.

Howard

2. Programmer Needed ASAP

3. xsd.exe generated classes

4. Good resources for using AD for both W2K and NW services

5. How to "cast" to System.Xml.XmlElement from a xsd.exe generated class?

6. More on Chem Plant Muzzle Law

7. Overriding the names of classes/ properties generated by XSD.exe

8. GIF animation

9. xsd.exe - schema choice and generated classes

10. XSD.exe fails to generate C# code for this XSD schema

11. Generating a Base class for a xsd generated Class

12. WSDL.EXE / XSD.EXE and <xsd:import> tag

13. Does XSD.EXE/WSDL.EXE support <xsd:include>/<xsd:import>?