Monday, February 27, 2023

XSD schema for list of objects using ComplexType

 HOWTO

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:foo="foo.schema.myproject"
           targetNamespace="foo.schema.myproject" elementFormDefault="unqualified" attributeFormDefault="unqualified">
    <xs:element name="DaveObjectList" type="foo:DaveObjectListType">
        <xs:annotation>
            <xs:documentation>ROOT: DaveObjectList</xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="DaveObject" type="foo:DaveObjectType">
        <xs:annotation>
            <xs:documentation>Dave Object Type</xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:complexType name="DaveObjectType">
        <xs:attribute name="newDaveObject" type="xs:string" use="required"/>
        <xs:attribute name="timestamp" type="xs:dateTime" use="required"/>
    </xs:complexType>
    <xs:complexType name="DaveObjectListType">
        <xs:annotation>
            <xs:documentation>List  of type DaveObjectType</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element ref="foo:DaveObject" minOccurs="0" maxOccurs="9999"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

Generated XML document

 Using https://www.liquid-technologies.com/online-xsd-to-xml-converter

<!--Created with Liquid Technologies Online Tools 1.0 (https://www.liquid-technologies.com)-->
<daveobjectlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="foo.schema.myproject" xsi:schemalocation="foo.schema.myproject schema.xsd">
  <daveobject newdaveobject="string" timestamp="2005-09-03T21:00:34.28"></daveobject>
  <daveobject newdaveobject="string" timestamp="2016-10-14T06:28:07.37">
</daveobject></daveobjectlist>