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

XML文件验证报错:无法解析vi:visitaType组件的解决方法咨询

修复XML验证错误:src-resolve.4.2无法解析vi:visitaType

错误信息

Error:(17, 69) src-resolve.4.2: Error resolving component 'vi:visitaType'. It was detected that 'vi:visitaType' is in namespace 'http://www.clinica/visita', but components from this namespace are not referenceable from schema document 'file:/C:/Users/studio/Documents/psw_esercitazioni%20personali/xml%20schema/testEsame1s/clinica.xsd'. If this is the incorrect namespace, perhaps the prefix of 'vi:visitaType' needs to be changed. If this is the correct namespace, then an appropriate 'import' tag should be added to 'file:/C:/Users/studio/Documents/psw_esercitazioni%20personali/xml%20schema/testEsame1s/clinica.xsd'.

修复步骤

1. 给clinica.xsd添加命名空间导入

当前clinica.xsd引用了vi:visitaType,但未导入对应命名空间的Schema文件,需在<xsd:schema>标签内添加导入语句:

修改后的clinica.xsd:

<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns="http://www.clinica/clinica"
        targetNamespace="http://www.clinica/clinica"
        xmlns:vi="http://www.clinica/visita">

    <!-- 添加命名空间导入 -->
    <xsd:import namespace="http://www.clinica/visita" schemaLocation="visita.xsd"/>

    <xsd:element name="clinica" type="clinicaType"/>
    <xsd:complexType name="clinicaType">
        <xsd:sequence>
            <xsd:element name="giorno" type="xsd:date"/>
            <xsd:element name="visiteGiorno" type="vgType"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="vgType">
        <xsd:sequence>
            <xsd:element name="visitaSingola" type="vi:visitaType"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

2. 修正XML文件的schemaLocation及元素前缀

原XML存在两处问题:

  • schemaLocation错误将http://www.clinica/visita指向clinica.xsd,需改为指向visita.xsd,同时补充自身命名空间的Schema映射
  • 子元素未添加对应命名空间前缀,不符合Schema定义

修改后的XML文件:

<?xml version="1.0" encoding="UTF-8" ?>
<cli:clinica xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xmlns:cli="http://www.clinica/clinica"
              xmlns:vi="http://www.clinica/visita"
              xmlns:an="http://www.clinica/animale"
              xmlns:pe="http://www.clinica/persona"
              xsi:schemaLocation="http://www.clinica/clinica clinica.xsd
                                  http://www.clinica/visita visita.xsd">
    <cli:giorno>2023-06-14</cli:giorno>
    <cli:visiteGiorno>
        <cli:visitaSingola>
            <vi:idVisita>33</vi:idVisita>
            <vi:costo>33</vi:costo>
            <vi:proprietario>
                <pe:nome>giorgio</pe:nome>
                <pe:datiBancari>test</pe:datiBancari>
                <pe:indirizzo>test</pe:indirizzo>
            </vi:proprietario>
            <vi:animale>
                <an:specie>test</an:specie>
                <an:sesso>test</an:sesso>
                <an:numero>33</an:numero>
            </vi:animale>
        </cli:visitaSingola>
    </cli:visiteGiorno>
</cli:clinica>

说明:visitaSingola下的子元素用vi:前缀匹配visita命名空间;proprietario和animale下的元素分别用pe:、an:前缀,对应各自的Schema定义。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 23:52:53