【问题标题】:xsi:schemaLocation element type not boundxsi:schemaLocation 元素类型未绑定
【发布时间】:2015-08-03 06:24:01
【问题描述】:

对 xml 很陌生。验证器抛出错误。

完全错误与元素类型“mpreader”关联的属性“xsi:schemaLocation”的前缀“xsi”未绑定。

这是 xml 的剪辑

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mpreader xmlns="C:\Users\Dallan\Desktop\Mpreader\" xmlns:xs="http://www.w3.org/20one/XMLSchema-instance" 
 xsi:SchemaLocation="C:\Users\Dallan\Desktop\Mpreader\mpreaderschemafinal.xsd"> 

            <firmware>"3.4.16"</firmware>  
            <hardware>"2.3.53"</hardware>
            <sn>"234-1three5"</sn>

还有一个xsd的剪辑

    <?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="C:Users/Dallan/Desktop/Mpreader/" elementFormDefault="qualified" targetNamespace="C:\Users\Dallan\Desktop\Mpreader\">

<xs:element name="mpreader">
<xs:complexType>
<xs:sequence maxOccurs="unbounded">
    <xs:element name="firmware" type="xs:string"/>
    <xs:element name="hardware" type="xs:string"/>
    <xs:element name="sn" type="xs:string"/>
    <xs:element name="devices">
        </xs:sequence>
        </xs:complexType>
        </xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

【问题讨论】:

  • 您可以尝试在 xs:schema 元素中将 'targetNamespace="C:\Users\Dallan\Desktop\Mpreader\" ' 添加到您的 xsd 中吗?
  • 没有用。 标签的语法是否正确?这就是验证器似乎遇到的问题
  • 我的猜测是这是一个命名空间问题。这就是我建议的原因。也许另一个您可以尝试验证它的想法是从您的 XML 中删除默认命名空间和命名空间位置。然后我们知道它是否确实是命名空间。

标签: xml schema


【解决方案1】:

我有一个类似的问题,我有一个需要用 JAXB 解析的自定义 XML。

为了正确解析,我需要添加 xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 命名空间。

我改变了这个:

<notifications xmlns="http://some/namespace">

到这里:

<notifications xmlns="http://some/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

我认为在您的情况下,您可能需要将它们都添加到缺少的地方。

【讨论】:

    猜你喜欢
    • 2016-10-12
    • 2018-09-12
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    • 1970-01-01
    • 2021-05-18
    相关资源
    最近更新 更多