derivedBy attribute in XML schema to create a list of basic types

130 views Asked by At

Good morning,

I am trying to understand how attribute "derivedBy" in a XML schema works to build a list of basic types, for instance a string.

I searched for working examples. There are not many examples online, but I found this one: https://www.brainbell.com/tutors/XML/XML_Book_B/Viewing_Schemas_in_XML_Tools.htm

Unfortunately, I could not make it work in two different files (.xml and xsd) and I need a working example:

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:simpleType name="StringList" base="xs:string" derivedBy="list" />

      <xs:complexType name="root">
        <xs:sequence>
          <xs:element type="StringList" name="myListElement"></xs:element>
        </xs:sequence>
      </xs:complexType>

      <xs:element name="root" type="root"></xs:element>
    </xs:schema>

And the xml document I'm trying to validate is:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="derivedBy.xsd">
  <myListElement>
   a b c
  </myListElement>
</root>

I'm trying to validate it with XML Tools plugin in Notepad++, but I'm getting an error I don't knwo how to fix:

Unable to parse schema file. Parsing error at line 3: Element '{http://www.w3.org/2001/XMLSchema}simpleType:The content is not valid. Expected is (annotation?, (restriction|list|union)).

What am I doing wrong? Besides, as I don't find much information online about derivedBy="list", does it mean it's not longer in use?

Thank you in advance for your help.

1

There are 1 answers

0
kimbert On BEST ANSWER

XML Schema 1.0 does not define any attribute with name 'derivedBy'. The specifications are here: Part 1 - Structures and Part 2 - Datatypes and no such attribute is mentioned anywhere in those documents.

If you want to describe a space-separate list of values in a tag then you need a list type:

Your simple type definition therefore needs to look similar to this:

<xs:simpleType name="StringList">
    <xs:list itemType="xs:string">
</xs:simpleType>