1

I have a XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified"
       elementFormDefault="qualified">
<xs:element name="Structure">
    <xs:annotation>
        <xs:documentation>Comment describing your root element</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" ref="Tag1"/>
            <xs:element maxOccurs="unbounded" minOccurs="0" ref="Tag2"/>
            <xs:element minOccurs="0" ref="Properties"/>
            <xs:element minOccurs="0" ref="Tag3"/>
        </xs:sequence>
        <xs:attribute name="url"/>
    </xs:complexType>
</xs:element>
<xs:element name="Tag1">
    <xs:complexType>
        <xs:attribute name="attr"/>
        <xs:attribute name="attr2"/>
    </xs:complexType>
</xs:element>
<xs:element name="Tag2">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
            <xs:element minOccurs="0" ref="Object"/>
            <xs:element maxOccurs="unbounded" minOccurs="0" ref="Tag2"/>
        </xs:sequence>
        <xs:attribute name="filter"/>
    </xs:complexType>
</xs:element>
<xs:element name="Object">
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" name="tag35">
                <xs:complexType>
                    <xs:sequence minOccurs="0">
                        <xs:element maxOccurs="unbounded" minOccurs="0" ref="Tag3"/>
                    </xs:sequence>
                    <xs:attribute name="attr4"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="attr48"/>
    </xs:complexType>
</xs:element>

<xs:element name="element52">
    <xs:annotation>
        <xs:documentation>Text54</xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element minOccurs="0" ref="el58"/>
        </xs:sequence>
        <xs:attribute name="vector"/>
    </xs:complexType>
</xs:element>
<xs:element name="el66" type="el66Type"/>
<xs:element name="el58">
    <xs:complexType mixed="true">
        <xs:attribute name="ID" type="xs:string"/>
    </xs:complexType>
</xs:element>
<xs:element name="Tag3">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
            <xs:element minOccurs="0" name="MetaProperty">
                <xs:complexType>
                    <xs:sequence minOccurs="0">
                        <xs:any/>
                    </xs:sequence>
                    <xs:attribute name="name"/>
                    <xs:attribute name="value"/>
                </xs:complexType>
            </xs:element>
            <xs:element minOccurs="0" ref="Property"/>
        </xs:sequence>
        <xs:attribute name="ID"/>
        <xs:attribute name="language" use="optional"/>
    </xs:complexType>
</xs:element>
<xs:element name="Property">
    <xs:complexType>
        <xs:sequence minOccurs="0">
            <xs:any minOccurs="0" processContents="skip"/>
        </xs:sequence>
        <xs:attribute name="name"/>
        <xs:attribute name="type"/>
    </xs:complexType>
</xs:element>
<xs:element name="Properties">
    <xs:complexType>
        <xs:sequence maxOccurs="unbounded" minOccurs="0">
            <xs:element minOccurs="0" ref="Property"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:complexType mixed="true" name="el66Type">
    <xs:attribute name="ID" type="xs:string"/>
</xs:complexType>   
</xs:schema>

And an xml:

<Structure url="/Test/url">
<Tag1/>
<Tag2>
    <Object>
        <tag35/>
    </Object>
</Tag2>
<Properties>
    <Property name="bla" type="value1"/>
    <Property name="bla2" type="value2"/>
</Properties>
</Structure>

I am doing a validation, and I am getting the following error:

org.xml.sax.SAXParseException; cvc-complex-type.2.4.a: Invalid content was found starting with element 'Tag2'. One of '{Tag1, Tag2, Tag3}' is expected.

I checked in previous questions and always the solution is related with elementFormDefault="qualified" but now it is not the case so, could it be possible that there is a bug there? Any clue, will be grateful.

MarcosTonina
  • 351
  • 1
  • 3
  • 16
  • Hmm, "like this" is not so good as we would need to guess what is real and what is simplified, so "exactly" would be needed. Can you reproduce the problem with very simple example XSD and XML and paste those here? – Markus Benko Feb 21 '17 at 20:29
  • 2
    elementFormDefault: (a) it has no effect unless there is a targetNamespace for the schema, which yours does not; (b) it only affects local element declarations (using name= rather than ref=) and there aren't any in your schema. So I don't think that's the problem. But without a repro, I don't know what is. – Michael Kay Feb 21 '17 at 22:56

1 Answers1

0

Your XML is valid against your XSD as posted in your question.

The error message in your question would not be returned. It must have been from different XML or XSD documents.

As Michael Kay states in the comments:

  • elementFormDefault only affects local elements declarations.
  • elementFormDefault only comes into play when the XSD has a targetNamespace.

For more details about elementFormDefault see this answer.

kjhughes
  • 106,133
  • 27
  • 181
  • 240