0

I am trying to create classes from a xsd file using xsd.exe, but get this:

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

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSpy v2008 sp1 (http://www.altova.com) by (EMBRACE) -->
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns1="http://comp.com/service/model/extension" targetNamespace="http://comp.com/service/model/extension">
    <xs:complexType name="attachment">
        <xs:sequence>
            <xs:element name="fileIdentifier" type="xs:string" minOccurs="0"></xs:element>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="metadataSystem">
        <xs:sequence>
            <xs:element name="activityId" type="xs:string" minOccurs="0"></xs:element>
            <xs:element name="from" type="xs:long" minOccurs="0"></xs:element>
            <xs:element name="href" type="xs:string" minOccurs="0"></xs:element>
            <xs:element name="performers" type="xs:long" minOccurs="0"></xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Where I have this top-level elements? If I add:

<xs:element name="attachment" type="attachment" />

I get this:

Missing type "attachment"


This question don't help, adding element tag throw new error.

Community
  • 1
  • 1
  • Possible duplicate of [Cannot generate classes because no top-level elements with complex type where found](http://stackoverflow.com/questions/32395215/cannot-generate-classes-because-no-top-level-elements-with-complex-type-where-fo) – Raskayu Aug 10 '16 at 06:36
  • I have seen this question, but adding element tag don't help me. – Sergey Rubtsov Aug 10 '16 at 07:30
  • I think it's not quite a duplicate, at least not with this one other question, because there is an issue with the top-level element declaration as well. – Ghislain Fourny Aug 10 '16 at 07:34

1 Answers1

0

When declaring an element, the type must be referred to with its fully qualified name, that is, the prefix ns1, bound to the target namespace, was missing before attachment in the type attribute.

This is a common source of confusion, since the declaration of types (the name attribute) is always done with the local name only, the namespace part being always the target namespace of the schema when available.

<xs:element name="attachment" type="ns1:attachment" />

The prefix can only be omitted if the namespace of the type is declared as the default namespace with an xmlns attribute.

Ghislain Fourny
  • 6,971
  • 1
  • 30
  • 37
  • You're welcome. If you wish to read more, you may find this useful, as stackoverflow has a new documentation feature: http://stackoverflow.com/documentation/xml/1593/namespaces#t=201608100756464310019 – Ghislain Fourny Aug 10 '16 at 07:57