0
votes

Good day to you fellow programmers, I am introducing myself in the wonders of XML and XML Schema. I am trying to make the .xsd so that my servlet can deal with the information contained on the XML.

I have been using this website to validate my work: https://www.corefiling.com/opensource/schemavalidate/

The problem lies in the next 5 problems that I cannot solve. They might be fairly easy to solve but I quite new to this so I've struggling for a couple of days without making too much progress. The errors are as follow:

Line 16: s4s-elt-must-match.1: The content of 'Pais' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: attribute.

Line 64: src-resolve: Cannot resolve the name 'Titulo' to a(n) 'element declaration' component.

Line 65: src-resolve: Cannot resolve the name 'ip' to a(n) 'element declaration' component.

Line 69: s4s-elt-must-match.1: The content of 'OtraPelicula' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref)*)). A problem was found starting at: attribute.

Line 73: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Pais'. One of '{Pelicula}' is expected.

The XML looks like this:

2001

  <Pelicula ip="vpg001" langs="en fr">
    <Titulo>Los gemelos golpean dos veces</Titulo>
    <Generos> <Genero>Comedia</Genero> <Genero>Aventuras</Genero> </Generos>
    <Duracion>105</Duracion>
    <Reparto> 
      <Nombre>Debito, Dani</Nombre>
      <Personaje>suarez</Personaje>
      <Oscar>Principal</Oscar>
      Austin, EEUU
      <OtraPelicula anio="2009">
           <Titulo>El aprendiz</Titulo>
           <MML>mml2009.xml</MML>
     </OtraPelicula>
    </Reparto>
    <Reparto>
      Viena, Austria
      <Nombre>Suarsenager, Arnold</Nombre>
      <Personaje>neymar</Personaje>
    </Reparto>
  </Pelicula>


  <Pelicula ip="ter003" langs="en it">
    <Titulo>Terminator</Titulo>
    <Generos> <Genero>Comedia</Genero> <Genero>Aventuras</Genero> </Generos>
    <Duracion>140</Duracion>
    <Reparto> 
      <Nombre>Suarsenager, Arnold</Nombre>
      <Personaje>carvajal</Personaje>
      <Oscar>Principal</Oscar>
      Viena, Austria
    </Reparto>
    <Reparto> 
      <Nombre>Pit, Braz</Nombre>
      Baltimore, EEUU
      <Personaje>zidane</Personaje>
    </Reparto>
    <Reparto> 
      <Nombre>Winsle, Keit</Nombre>
      <Personaje>sofĂ­a</Personaje>
      <Oscar>Secundario</Oscar>
      Londres, UK
    </Reparto>
  </Pelicula>

and my XSD so far, after all the debugging has this shape:

    <?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:element name="Anio">
        <xs:simpleType>
            <xs:restriction base="xs:decimal">
                <xs:minInclusive value="1900"/>
                <xs:maxInclusive value="2017"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element> <!-- Ver si esto se puede dejar asi -->
    <xs:element name="Movies">
        <xs:complexType>
            <xs:sequence>
    <xs:element ref="Anio"/>
    <xs:element name="Pais">
        <xs:attribute name="pais" type="xs:string" use="required"/>
        <xs:attribute name="lang" use="required">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:pattern value="(?i)^[A-Z]{2}$"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:attribute>
    </xs:element>
    <xs:element name="Pelicula">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Titulo" type="xs:string"/> <!-- Contedrá texto signfica que tiene que tenerlo si o si? -->
                <xs:element name="Genero">
                    <xs:simpleType>
                        <xs:restriction base="xs:string">
                            <xs:enumeration value="Comedia"/>
                            <xs:enumeration value="Drama"/>
                            <xs:enumeration value="Aventuras"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="Duracion" >
                    <xs:simpleType>
                        <xs:restriction base="xs:integer">
                            <xs:minInclusive value="1"/>
                            <xs:maxExclusive value="300"/>
                        </xs:restriction>
                    </xs:simpleType>
                </xs:element>
                <xs:element name="Reparto" maxOccurs="unbounded" minOccurs="0">
                    <xs:complexType mixed="true">
                        <!-- Como ponemos la restriccion para la ciudad natal del actor -->
                        <xs:sequence>
                                    <!-- Nombre es obligatorio, ver que hacer con el despues-->
                            <xs:element name="Nombre" type="xs:string"/>
                            <xs:element name="Personaje" type="xs:string" />
                            <xs:element name="Oscar">
                                <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                        <xs:enumeration value="Principal"/>
                                        <xs:enumeration value="Secundario"/>
                                    </xs:restriction>
                                </xs:simpleType>
                            </xs:element>
                            <xs:element name="OtraPelicula">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element ref="Titulo"/>
                                        <xs:element ref="ip"/>
                                        <xs:element name="MML" type="xs:string"/>
                                    </xs:sequence>
                                </xs:complexType>
                                <xs:attribute name="anio" type="xs:integer" minOccurs="1" maxOccurs="unbounded"/>
                            </xs:element>
                        </xs:sequence>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute name="ip" use="required">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:pattern value="[a-zA-Z]{3}\d{3}"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
            <xs:attribute name="langs">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:pattern value=""/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

Thank you for your time.

1

1 Answers

0
votes

Line 16: s4s-elt-must-match.1: The content of 'Pais' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref))). A problem was found starting at: attribute.*

You can't declare attributes directly within an element. You need to define a complexType and declare the attribute within the complexType.

Line 64: src-resolve: Cannot resolve the name 'Titulo' to a(n) 'element declaration' component.

The ref attribute must refer to a global element declaration (a child of xs:schema) not to a local declaration.

Line 65: src-resolve: Cannot resolve the name 'ip' to a(n) 'element declaration' component.

Ditto (the only thing I see named "ip" is an attribute).

Line 69: s4s-elt-must-match.1: The content of 'OtraPelicula' must match (annotation?, (simpleType | complexType)?, (unique | key | keyref))). A problem was found starting at: attribute.*

Same as the line 16 problem.

Line 73: cvc-complex-type.2.4.a: Invalid content was found starting with element 'Pais'. One of '{Pelicula}' is expected.

This looks like an instance validation error: I don't see how you can be doing validation if the schema has the above errors.