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?
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).
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.
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.
The list element defines a simple type element as a list of values of a specified data type.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With