Tuesday, September 09, 2014

Error E2001 - The schema does not contain any 'elements' so will not generate any classes

If you run the Liquid XML Data Binder and get error E2001, it means you need to add at least 1 element in order to generate your C#, C++, Java, VB .Net or Visual Basic 6 classes.

As explained in yesterdays blog Element vs complexType, you may only validate an xml document if your schema contains an element which describes each item (tag) used within the document.

Wizard Error E2001


The schema does not contain any 'elements' so will not generate any classes.


Xml Schema elements can be considered as objects that have a type defined by the simple and complex types. So if no elements are specified in the schema, no classes will be generated as the optimiser will determine that none of the declared complexTypes will never be utilised.


The solution is to declare elements within the schema.

E.g. The following Xml Schema (XSD) will not generate any classes as no elements are defined.

<?xml version="1.0" encoding="utf-8"?>
  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
   <xs:complexType name="Item">
       <xs:element name="Description" type="xs:string"/>
       <xs:element name="Quantity" type="xs:unsignedLong"/>
   <xs:complexType name="QuotedItem">
       <xs:element name="Item" type="Item"/>
       <xs:element name="PricePerItemInPence" type="xs:unsignedLong" minOccurs="0"/>
       <xs:element name="CurrentAvalibility" type="xs:unsignedLong" minOccurs="0"/>

However, by extending the schema to define the element QuoteRequest and its associated child elements, a full class hierarchy will be generated:

  <xs:element name="QuoteRequest">
         <xs:element name="CustomerID" type="xs:string"/>
         <xs:element name="Item" type="Item" minOccurs="0" maxOccurs="unbounded"/>

See Also

Elements vs complexTypes