'XML and XSD mistake

i need help to solve my error with this code of XML and XSD, please if u can check it and tell me a solution of why it doesn't works am gona be your slave this is my XSD code:

<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
  <xs:element name="clients">
<xs:complexType>
  <xs:sequence>
    <xs:element name="client" type="xs:string" maxOccurs="unbounded"/>
  <xs:complexType>
             <xs:sequence>
             <xs:element name="llinatge" type="xs:string"/>
             <xs:element name="edat" type="xs:decimal"/>
             <xs:element name="data_naixement" type="xs:date"/>
             <xs:element name="email" type="xs:string"/>
             <xs:element name="telefon" type="xs:decimal"/>
             </xs:sequence>
                <xs:attribute name="poblacio" type="xs:string" use="required"/>
                <xs:attribute name="codi" type="xs:string" use="required"/>
       </xs:complexType>
    </xs:sequence>
  </xs:complexType>
  </xs:element>
  </xs:schema>

This is my XML code:

<?xml version="1.0" ?>
<clients
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="clients.xsd">

   <client codi="001">
   <llinatge>Alomar</llinatge>
   <edat>30</edat>
  <data_naixement poblacio="Palma de Mallorca">3-10-1989</data_naixement>
      <email>[email protected]</email>
  <telefon>600898989</telefon>


  </client>
   <client codi="002">
      <llinatge>Pérez</llinatge>
      <edat>47</edat>
      <data_naixement poblacio="Ciutadella">3-10-1975</data_naixement>
      <email>[email protected]</email>
  <telefon>600898989</telefon>
  
   </client>
</clients>


Solution 1:[1]

Based upon the XML shown and what you have attempted in your XSD, I would recommend something like this:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> 
    <xs:element name="clients">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="client" maxOccurs="unbounded" >
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="llinatge" type="xs:string"/>
                            <xs:element name="edat" type="xs:decimal"/>
                            <xs:element name="data_naixement">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute name="poblacio" type="xs:string" use="required"/>
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="email" type="xs:string"/>
                            <xs:element name="telefon" type="xs:decimal"/>
                        </xs:sequence>    
                        <xs:attribute name="codi" type="xs:string" use="required"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Note that for the data_naixement I have it extending xs:string instead of xs:date, since those date values are not in the correct format YYYY-MM-DD. You could either assert some pattern restriction or correct the date format and change the type, depending upon what you are really expecting those values to be.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mads Hansen