You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSD转PHP遇src-resolve错误:无法解析tab:codigoUnidGestora类型

问题:XSD转PHP时出现src-resolve类型解析错误

转换XSD到PHP时遇到以下错误:

src-resolve: Cannot resolve the name 'tab:codigoUnidGestora' to a(n) 'type definition' component.xsd(src-resolve)

主文件Educacao.xsd代码

<xsd:schema targetNamespace="http://www.tce.se.gov.br/sagres2022/xml/sagresEdu" version="1.0"
xml:lang="pt-BR"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:edu="http://www.tce.se.gov.br/sagres2022/xml/sagresEdu"
xmlns:gen="http://www.tce.se.gov.br/sagres2022/xml/genericos"
xmlns:tab="http://www.tce.se.gov.br/sagres2022/xml/tabelasInternas"
elementFormDefault="qualified">

<xsd:import namespace="http://www.tce.se.gov.br/sagres2022/xml/genericos"
    schemaLocation="Genericos.xsd" />
<xsd:import namespace="http://www.tce.se.gov.br/sagres2022/xml/tabelasInternas"
    schemaLocation="tabelasInternas.xsd" />

    ...

<xsd:complexType name="cabecalho_t">
    <xsd:sequence>
        <xsd:element nillable="false" name="codigoUnidGestora" type="tab:codigoUnidGestora"/>
        <xsd:element nillable="false" name="nomeUnidGestora" type="gen:nomeUnidGestora_t" />
        <xsd:element nillable="false" name="cpfContador" type="gen:cpfContador_t" />
        <xsd:element nillable="false" name="cpfGestor" type="gen:cpfGestor_t" />
        <xsd:element nillable="false" name="anoReferencia" type="gen:anoReferencia_t" />
        <xsd:element nillable="false" name="mesReferencia" type="gen:mesReferencia_t" />
        <xsd:element nillable="false" name="versaoXml" type="gen:versaoXml_t" />
        <xsd:element nillable="false" name="diaInicPresContas" type="gen:diaInicPresContas_t" />
        <xsd:element nillable="false" name="diaFinaPresContas" type="gen:diaFinaPresContas_t" />
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="educacao_t">
    <xsd:sequence>
        <xsd:element name="PrestacaoContas" type="edu:cabecalho_t" />
        <xsd:element name="escola" type="edu:escola_t" maxOccurs="unbounded" />
        <xsd:element name="atendimento" type="edu:atendimento_t" minOccurs="0"
            maxOccurs="unbounded" />
    </xsd:sequence>
</xsd:complexType>

<!-- ROOT -->
<xsd:element name="educacao" type="edu:educacao_t">
    <xsd:unique name="chaveAluno">
        <xsd:selector xpath="edu:escola/edu:turma/edu:matricula/edu:aluno" />
        <xsd:field xpath="edu:cpfAluno" />
    </xsd:unique>
</xsd:element>
</xsd:schema>

tabelasInternas.xsd代码

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema elementFormDefault="qualified" 
targetNamespace= 
"http://www.tce.se.gov.br/sagres2023/xml/tabelasInernas" 
version="1.0" xml:lang="pt-BR" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:edu="http://www.tce.se.gov.br/sagres2022/xml/sagresEdu">
<xsd:simpleType name="codigoUnidGestora">
    <xsd:restriction base="xsd:string">
            <xsd:enumeration value="201031"/>
            <xsd:enumeration value="201050"/>        
    </xsd:restriction>
</xsd:simpleType> 
</xsd:schema>

错误原因排查

问题核心是命名空间完全不匹配:

  • 主文件中tab前缀绑定的命名空间是http://www.tce.se.gov.br/sagres2022/xml/tabelasInternas,导入语句也指向该命名空间
  • 但tabelasInternas.xsd的targetNamespace存在两处错误:
    1. 年份不一致:主文件用2022,子文件写的是2023
    2. 拼写错误:tabelasInernas少了一个t,正确应为tabelasInternas

修正方案

修改tabelasInternas.xsd的targetNamespace,使其与主文件导入的命名空间完全一致:

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema elementFormDefault="qualified" 
targetNamespace="http://www.tce.se.gov.br/sagres2022/xml/tabelasInternas" 
version="1.0" xml:lang="pt-BR" 
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:edu="http://www.tce.se.gov.br/sagres2022/xml/sagresEdu">
<xsd:simpleType name="codigoUnidGestora">
    <xsd:restriction base="xsd:string">
            <xsd:enumeration value="201031"/>
            <xsd:enumeration value="201050"/>        
    </xsd:restriction>
</xsd:simpleType> 
</xsd:schema>

额外确认:

  • tabelasInternas.xsd的文件路径与主文件schemaLocation指定的路径一致
  • 主文件xsd:import的namespace属性值和子文件targetNamespace完全匹配(包括大小写、拼写、年份)

内容的提问来源于stack exchange,提问作者Nathan Santos

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 08:31:18