0

I have an issue with a simple XSD loaded via a XmlSchemaSet object and XML paresed using a XmlReaderSettings

Here is my XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="A">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="B">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="C" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType mixed="true">
                  <xs:sequence>
                    <xs:element name="Properties" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="Item" minOccurs="0">                            
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

This following XML will generate an error on line 5 ("Could not find schema information for the attribute 'Name'.at line 5:11 :

<A>
    <B>
        <C>
            <Properties>
                <Item Name="OBJECT">
                    <Item Name="CONTENT"/>
                </Item>
            </Properties>
        </C>
    </B>
</A>

What is wrong in my XSD?

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
MikyMike
  • 1
  • 1

3 Answers3

0

You need to define the schema for the Item element.

Richard Schneider
  • 34,944
  • 9
  • 57
  • 73
0

You are missing an definition for the second level Item and it's attributes.

The following should be under your top level item

                        <xs:complexType>
                          <xs:sequence>
                            <xs:element name="Item">
                              <xs:complexType>
                                <xs:attribute name="Name" type="xs:string" use="required" />
                              </xs:complexType>
                            </xs:element>
                          </xs:sequence>
                          <xs:attribute name="Name" type="xs:string" use="required" />
                        </xs:complexType>

So it looks like this

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="A">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="B">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="C" minOccurs="0" maxOccurs="unbounded">
                <xs:complexType mixed="true">
                  <xs:sequence>
                    <xs:element name="Properties" minOccurs="0">
                      <xs:complexType>
                        <xs:sequence>
                          <xs:element name="Item" minOccurs="0">                            
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element name="Item">
                                  <xs:complexType>
                                    <xs:attribute name="Name" type="xs:string" use="required" />
                                  </xs:complexType>
                                </xs:element>
                              </xs:sequence>
                              <xs:attribute name="Name" type="xs:string" use="required" />
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Either that, or your first Item should be self terminating if you only want one level of item. But even so you then have to define the attributes.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
0

I think that nothing is wrong with your XSD, and something is wrong with your schema processor. Here is what Saxon reports:

Saxon-EE 9.8.0.3J from Saxonica
Java version 1.8.0_121
Using license serial number V005192
Loading schema document file:/Users/mike/Desktop/temp/test.xsd
Finished loading schema document file:/Users/mike/Desktop/temp/test.xsd
Schema checking successful. Time: 738ms. Memory: 37Mb.
Using parser org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser
Processing file:/Users/mike/Desktop/temp/test.xml
Validation time: 244ms. Memory: 40Mb.
Validation successful

Your element declaration for Item has neither a simpleType or complexType child, nor a type attribute. The relevant rule in XSD part 1 is in §3.3.2, where it says that the effective {type definition} is:

The type definition corresponding to the <simpleType> or <complexType> element information item in the [children], if either is present, otherwise the type definition ·resolved· to by the ·actual value· of the type [attribute], otherwise the {type definition} of the element declaration ·resolved· to by the ·actual value· of the substitutionGroup [attribute], if present, otherwise the ·ur-type definition·.

So in this case it is "the ·ur-type definition·", which is just a fancy name for xs:anyType (see §3.4.7) which allows any content.

Sadly Microsoft haven't updated their schema processor for about 15 years and bugs like this are not unknown.

This suggests you have 3 ways forward:

  • Submit a bug to Microsoft and wait 15 years for a resolution

  • Switch to a different schema processor (e.g. Saxon)

  • Work around the bug by declaring the required type for element Item.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164