【问题标题】:XSD error: unsupported protocol in URLXSD 错误:URL 中不支持的协议
【发布时间】:2018-12-02 00:19:20
【问题描述】:

我的 XML 和 XSD 有问题。

我正在尝试在我的架构中使用 XHTML 标记 <img>,但我无法导入 XHTML 架构。验证器给我的错误是:

第 0 行第 0 列出现致命错误,URL 中的协议不受支持。

下一个是复制我的问题的最小示例。

这是文件.xsd:

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

<xsd:import namespace="http://www.w3.org/1999/xhtml" 
schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" />

<xsd:element name="tag" >
 <xsd:complexType>
  <xsd:sequence>
   <xsd:element ref="xhtml:img" />    
  </xsd:sequence>  
 </xsd:complexType>
</xsd:element>
</xsd:schema>

还有这个文件.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<tag xmlns:xsi="w3.org/2001/XMLSchema- instance" 
xmlns:xhtml="w3.org/1999/xhtml"; xsi:noNamespaceSchemaLocation="file.xsd"> 
  <xhtml:img href="http://" /> 
</tag>

【问题讨论】:

    标签: xml xsd xhtml xsd-validation xml-validation


    【解决方案1】:

    您不想将整个 XML 文件放在 XHTML 名称空间中。 (而xsi:noNamespaceSchemaLocation 用于无论如何都没有命名空间的情况。)

    所以改变

    <file xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns="http://www.w3.org/1999/xhtml" 
          xsi:noNamespaceSchemaLocation="file.xsd">
    

    <file xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xmlns:xhtml="http://www.w3.org/1999/xhtml" 
          xsi:noNamespaceSchemaLocation="file.xsd">
    

    然后仅在 XHTML 元素上选择性地使用 xhtml 命名空间前缀。


    更新

    现在已将完整的 MCVE 添加到问题中,您的 XSD 和 XML 存在许多明显的问题:

    • xmlns:xhtml="w3.org/1999/xhtml"; 不应以 ; 结尾。
    • xmlns:xsi 声明有多种方式。

    等等

    这是一个有效的 XSD/XML 对,解决了上述问题和其他问题:

    XML

    <?xml version="1.0" encoding="UTF-8"?> 
    <tag xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:xhtml="http://www.w3.org/1999/xhtml" 
         xsi:noNamespaceSchemaLocation="file.xsd"> 
      <xhtml:img src="http://" alt=""/> 
    </tag>
    

    XSD

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns:xhtml="http://www.w3.org/1999/xhtml"
                elementFormDefault="qualified">
    
      <xsd:import namespace="http://www.w3.org/1999/xhtml" 
                  schemaLocation="http://www.w3.org/2002/08/xhtml/xhtml1-strict.xsd" />
    
      <xsd:element name="tag" >
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element ref="xhtml:img" />    
          </xsd:sequence>  
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>
    

    【讨论】:

    • 哦,是的,对不起...我正在以任何方式更改这些文件,但我忘记了。但是随着这种变化,验证错误也是一样的
    • 很难为未说明的问题找到一个好的解决方案。接下来查看重复链接,了解如何正确指定对本地 XSD 的引用。
    • 错误似乎在导入标签中,因为当我删除他时,验证器说我没有包含 xhtml 命名空间。但是包含它说:“第 0 行第 0 列的致命错误,URL 中不支持的协议。”
    • 在您生成重现问题的 minimal reproducible example 之前,追踪问题将比本网站需要更多的来回时间,我的耐心愿意支持。
    • 好的,我已经修改了答案,放了最小的例子。对不起,这是我的第一个答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2014-02-18
    • 2020-11-29
    • 1970-01-01
    • 2023-04-10
    相关资源
    最近更新 更多