Julss799 / PROJECTE1-DAM2

Projecte 1: Entrega 05/12/2022 - 07/12/2022
1 stars 0 forks source link

Implementar XSD #50

Closed Formeinstein13 closed 2 years ago

Formeinstein13 commented 2 years ago
public static String xsd(String[] liniesNoms) {
        //Hem fet la capsalera del xsd
        String xsd="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
                + "<xs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" elementFormDefault=\"qualified\">\r\n"
                + "  <xs:element name=\"dadesGenerades\">\r\n"
                + "    <xs:complexType>\r\n"
                + "      <xs:sequence>\r\n"
                + "        <xs:element ref=\"dades\"/>\r\n"
                + "      </xs:sequence>\r\n"
                + "    </xs:complexType>\r\n"
                + "  </xs:element>\n"
                + "  <xs:element name=\"dades\">\r\n"
                + "    <xs:complexType>\r\n"
                + "      <xs:sequence>\r\n"
                + "        <xs:element ref=\"Registre\" maxOccurs=\"unbounded\"/>\r\n"
                + "      </xs:sequence>\r\n"
                + "    </xs:complexType>\r\n"
                + "  </xs:element>\r\n"
                + "  <xs:element name=\"Registre\">\r\n"
                + "    <xs:complexType>\r\n"
                + "      <xs:sequence>\n";
        //fem aquest bucle per agafar els noms dels camps per ordre
        for (int i=0;i<liniesNoms.length;i++) {
            xsd=xsd+"        <xs:element name=\""+liniesNoms[i]+"\" type=\"xs:string\"/>\n";
        }
        //fem el tancaments finals
        xsd=xsd+"      </xs:sequence>\r\n"
                + "    </xs:complexType>\r\n"
                + "  </xs:element>\r\n"
                + "</xs:schema>\r";
        return xsd;
    }