【问题标题】:XSD problem - cannot find the declaration of root elementXSD 问题 - 找不到根元素的声明
【发布时间】:2020-11-07 11:31:54
【问题描述】:

我在根据我的 XML 架构验证我的 XML 文件时遇到问题。一切正常,只是它显示它找不到countries 根元素的声明。

这是我的 XML 文件的一部分:

<?xml version="1.0" encoding="UTF-8"?>

<countries xmlns="https://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="kraje.xsd">
    <!-- I don't paste everything that's inside the countries element 
         since it's not causing errors -->
</countries>

这是我的 XSD 文件的一部分:

<?xml version="1.0"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="countries" type="countriesType"/>

    <xs:complexType name="countriesType">
        <xs:sequence>
            <xs:element ref="country"/>
        </xs:sequence>
    </xs:complexType>

</xs:schema>

【问题讨论】:

    标签: xml xsd xsd-validation xml-validation


    【解决方案1】:

    XML

    由于您的 XML 位于 https://www.w3schools.com 命名空间中,因此请更改

    xsi:schemaLocation="kraje.xsd"
    

    到

    xsi:schemaLocation="https://www.w3schools.com kraje.xsd"
    

    XSD

    添加匹配的targetNamespace,

    targetNamespace="https://www.w3schools.com"
    

    到xs:schema 根元素。

    另见

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      • 1970-01-01
      • 2021-09-07
      • 2019-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多