将xsd架构转换为xml

时间:2015-10-15 10:10:14

标签: xml excel xsd excel-2010

我有三个XSD文件和一个大的excel文件48k行。 如何根据XSD文件生成xml文件。

编辑:当我使用excel来完成这项工作时,它会给我一个错误"列表列表"

主xsd文件

<xs:include schemaLocation="Rosto.xsd"/>

<!-- Declaracao -->
<xs:element name="Modelo2">
    <xs:annotation>
        <xs:documentation>
            Modelo 2 IMI - Declaração de Contratos de Fornecimento
        </xs:documentation>
    </xs:annotation>
    <xs:complexType>
        <xs:sequence>
            <xs:element name="Rosto" type="RostoType" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
</xs:element>

Secundary xsd

<xs:simpleType name="NIFType">
    <xs:restriction base="xs:positiveInteger">
        <xs:totalDigits value="9"/>
        <xs:minInclusive value="100000000"/>
        <xs:maxInclusive value="999999999"/>
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="TrimestreType">
    <xs:annotation>
        <xs:documentation>
            03T - 1º Trimestre
            06T - 2º Trimestre
            09T - 3º Trimestre
            12T - 4º Trimestre
        </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
        <xs:length value="3"/>
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="CodTipoEntidadeType">
    <xs:annotation>
        <xs:documentation>
            201 - Entidade Fornecedora de Água
            202 - Entidade Fornecedora de Eletricidade
            203 - Entidade Fornecedora de Gás
            204 - Entidade Fornecedora de Serviço Fixo de Telecomunicações
        </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:positiveInteger">
        <xs:totalDigits value="3"/>
        <xs:minInclusive value="201"/>
        <xs:maxInclusive value="204"/>
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="CodTipoContratoType">
    <xs:annotation>
        <xs:documentation>
            501 - Contrato de inicio do fornecimento
            502 - Contrato de alteração do fornecimento
            503 - Cessacao do fornecimento
            504 - Contrato de ligação a rede de fornecimento
            505 - Outro
        </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:positiveInteger">
        <xs:totalDigits value="3"/>
        <xs:minInclusive value="501"/>
        <xs:maxInclusive value="505"/>
    </xs:restriction>
</xs:simpleType>

<xs:simpleType name="CodAmbitoContratoType">
    <xs:annotation>
        <xs:documentation>
            801 - Água - Contratos de fornecimento de água
            802 - Água - Contratos de ligação à rede de fornecimento de água
            803 - Água - Outro
            804 - Eletricidade - Contratos de fornecimento de eletricidade
            805 - Eletricidade - Contratos de ligação à rede elétrica
            806 - Eletricidade - Outro
            807 - Gás - Contratos de fornecimento de gás
            808 - Gás - Contratos de ligação à rede de fornecimento de gás
            809 - Gás - Outro
            810 - Telefones - Contratos de fornecimento de serviço fixo
            811 - Telefones - Contratos de ligação à rede de serviço fixo
            812 - Telefones - Outro
        </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:positiveInteger">
        <xs:totalDigits value="3"/>
        <xs:minInclusive value="801"/>
        <xs:maxInclusive value="812"/>
    </xs:restriction>
</xs:simpleType>

<xs:complexType name="IdClienteType">
    <xs:sequence>
        <xs:element name="idPaisResidencia" minOccurs="0">
            <xs:simpleType>
                <xs:annotation>
                    <xs:documentation>
                        Identificação do país de residência (ISO 3166)
                    </xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:string">
                    <xs:length value="2"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="nifCliente" type="NIFType" minOccurs="0">
            <xs:annotation>
                <xs:documentation>
                    NIF ou NIPC do cliente do declarante
                </xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="docIdentificacao" minOccurs="0">
            <xs:simpleType>
                <xs:annotation>
                    <xs:documentation>
                        Documento de identificação do não residente
                    </xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="100"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="nomeCliente" minOccurs="0">
            <xs:simpleType>
                <xs:annotation>
                    <xs:documentation>
                        Nome do não residente
                    </xs:documentation>
                </xs:annotation>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="170"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
    </xs:sequence>
</xs:complexType>

<xs:simpleType name="CodQualidadeClienteType">
    <xs:annotation>
        <xs:documentation>
            1001 - Proprietário, usufrutuário ou superficiário
            1002 - Arrendatário
            1003 - Subarrendatário
            1004 - Outros
        </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:positiveInteger">
        <xs:totalDigits value="4"/>
        <xs:minInclusive value="1001"/>
        <xs:maxInclusive value="1004"/>
    </xs:restriction>
</xs:simpleType>

<xs:complexType name="IdLocalAbastecidoType">
    <xs:sequence>
        <xs:element name="freguesia">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="6"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="tipo">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:length value="1"/>
                    <xs:enumeration value="U"/>
                    <xs:enumeration value="R"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="artigo" minOccurs="0">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="7"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="fraccao" minOccurs="0">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="5"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="seccao" minOccurs="0">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="7"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="arvCol" minOccurs="0">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="3"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <xs:element name="omisso" type="xs:boolean"/>
        <xs:element name="morada" minOccurs="0">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="3000"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
    </xs:sequence>
</xs:complexType>

Secundary xsd

<xs:include schemaLocation="Global.xsd"/>

<xs:complexType name="RostoType">
    <xs:sequence>
        <xs:element name="nif" type="NIFType">
            <xs:annotation>
                <xs:documentation>[1] - NIF da entidade declarante</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="trimestre" type="TrimestreType">
            <xs:annotation>
                <xs:documentation>[3] - Trimestre</xs:documentation>
            </xs:annotation>
        </xs:element>
        <!-- usar UTC -->
        <xs:element name="ano" type="xs:gYear">
            <xs:annotation>
                <xs:documentation>[4] - Ano</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="entidade" type="EntidadeType" minOccurs="0" maxOccurs="4">
            <xs:annotation>
                <xs:documentation>[2] - Entidade</xs:documentation>
            </xs:annotation>
        </xs:element>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="EntidadeType">
    <xs:sequence>
        <xs:element name="tipoEntidade" type="CodTipoEntidadeType"/>
        <xs:element name="linhas" type="EntidadeLinhaType" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
</xs:complexType>

<xs:complexType name="EntidadeLinhaType">
    <xs:sequence>
        <xs:element name="tipoContrato" type="CodTipoContratoType">
            <xs:annotation>
                <xs:documentation>[5] - Tipo de contrato ou ato</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="identificacaoDocumento">
            <xs:annotation>
                <xs:documentation>[6] - Identificação do documento</xs:documentation>
            </xs:annotation>
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:maxLength value="40"/>
                </xs:restriction>
            </xs:simpleType>
        </xs:element>
        <!-- usar UTC -->
        <xs:element name="dataContrato" type="xs:date">
            <xs:annotation>
                <xs:documentation>[7] - Data do contrato ou ato</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="ambitoContrato" type="CodAmbitoContratoType">
            <xs:annotation>
                <xs:documentation>[8] - Ambito do contrato ou ato</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="identificacaoCliente" type="IdClienteType">
            <xs:annotation>
                <xs:documentation>[9] - Identificacao do cliente</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="qualidadeCliente" type="CodQualidadeClienteType">
            <xs:annotation>
                <xs:documentation>[10] - Qualidade do cliente</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="identificacaoLocalAbastecido" type="IdLocalAbastecidoType">
            <xs:annotation>
                <xs:documentation>[11] - Identificacao do local abastecido</xs:documentation>
            </xs:annotation>
        </xs:element>
        <xs:element name="identificacaoProprietario" type="NIFType" minOccurs="0">
            <xs:annotation>
                <xs:documentation>[12] - Identificacao do proprietario do local abastecido</xs:documentation>
            </xs:annotation>
        </xs:element>
    </xs:sequence>
</xs:complexType>

1 个答案:

答案 0 :(得分:0)

使用XQuery,您应该能够根据需要生成XML输出,即使用模式导入和所有内容,您还应该能够根据模式对其进行验证。

您可以将Excel文件导出为CSV格式。开源Zorba引擎具有用于将CSV转换为XML或JSON的模块,并支持XML Schema验证。其他XQuery实现(Saxon,...)也可能支持从CSV文件导入数据。