Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Represent a List of Objects in XSD

Tags:

xml

xsd

How I can represent a list of objects in XSD, for example, given a XML like this?

 <msgBody>
  <Contato>
   <cdEndereco>11</cdAreaRegistro>
   <cdBairro>99797781</nrLinha>
   <email>[email protected]</email>
  </Contato>
  <Contato>
   <cdEndereco>11</cdAreaRegistro>
   <cdBairro>99797781</nrLinha>
   <email>[email protected]</email>
  </Contato>
 </msgBody>

How I can merge it into a list of object type Contato?

like image 908
Édipo Féderle Avatar asked Jan 19 '11 20:01

Édipo Féderle


People also ask

How do I give attributes in XSD?

The "use" property in the XSD definition is used to specify if the attribute is optional or mandatory. To specify that an attribute must be present, use="required" (Note: use may also be set to "prohibited", but we'll come to that later).

What is XSD anyType?

xsd:anyType example The xsd:anyType is the base data type from which all simple and complex data types are derived. It does not restrict the data content.

What is complexType and simpleType in XSD?

An element of type simpleType contains only text. It cannot have attributes and elements. An element of type complexType can contain text, elements, and attributes. An element of type complexType is parent to all the elements and attributes contained within it.

What is XSD list?

The list element defines a simple type element as a list of values of a specified data type.


1 Answers

I may suggest the following schema (even though your XML is broken as pasted):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="msgBody">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" ref="Contato"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="Contato">
    <xs:complexType>
      <xs:sequence>
        <xs:element ref="cdEndereco"/>
        <xs:element ref="cdBairro"/>
        <xs:element ref="email"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:element name="cdEndereco" type="xs:integer"/>
  <xs:element name="cdBairro" type="xs:integer"/>
  <xs:element name="email" type="xs:string"/>
</xs:schema>
like image 166
Lachezar Balev Avatar answered Sep 20 '22 05:09

Lachezar Balev