1

So I have this data.xml schema code:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://example.com" elementFormDefault="qualified">


<xs:element name="data">
<xs:complexType>
<xs:sequence>


<xs:element name="item" minOccurs="0" maxOccurs="unbounded">
  <xs:complexType>
    <xs:sequence>

      <xs:element name="title" type="xs:string" minOccurs="0" maxOccurs="1">
      </xs:element>

      <xs:element name="type" minOccurs="0" maxOccurs="1">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="header"/>
            <xs:enumeration value="normal"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

      <xs:element name="backgroundcolor" minOccurs="0" maxOccurs="1">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:pattern value="#[0-9A-Fa-f]+"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

      <xs:element name="fontcolor" minOccurs="0" maxOccurs="1">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:pattern value="#[0-9A-Fa-f]+"/>
          </xs:restriction>
        </xs:simpleType>
      </xs:element>

    </xs:sequence>
  </xs:complexType>
</xs:element>


</xs:sequence>
</xs:complexType>
</xs:element>


</xs:schema>

I have this test.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<j:data xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jeresapp.dk data.xsd" xmlns:j="http://example.com">

        <j:item>
        <j:title>test title</j:title>
        <j:backgroundcolor>#aaf8941e</j:backgroundcolor>
        <j:fontcolor>#ffffff</j:fontcolor>
        <j:type>header</j:type>
        </j:item>

</j:data>

I want 0-infinite number of item

Each item can contain 0-1 of each each child elements defined (e.g. title and fontcolor)

While I have worked tthrough some rrros (I am new to schemas, so I am picking up as I go) I am getting a bi of an odd error in various XSD validation tools:

Invalid content was found starting with element 'j:type'. No child element is expected at this point.

Tom
  • 3,587
  • 9
  • 69
  • 124

1 Answers1

0

use <all> instead of <sequence> to allow mixed order of child elements.

Spudley
  • 166,037
  • 39
  • 233
  • 307
Tom
  • 3,587
  • 9
  • 69
  • 124