XML XSD错误:org.xml.sax.saxparseexception:s4s-elt-schema-ns:el



我有一个非常简单的xml&XSD在解析过程中抛出以下错误。

org.xml.sax.saxparseexception:s4s-elt-schema-ns:名称空间 元素"配置"必须来自模式名称空间, 'http://www.w3.org/2001/xmlschema'。

XML进入这里:

   <?xml version="1.0" encoding="ISO-8859-1" ?> 
 <Config>
        <Test Script="final.sh" />
    </Config>

XSD到达这里:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Config">
        <xs:complexType>
        <xs:all> 
            <xs:element name="Test" minOccurs="0">
                <xs:complexType>
                    <xs:attribute name="Script" type="xs:string" use="required" />          
                </xs:complexType>
            </xs:element>
        </xs:all>
        </xs:complexType>
    </xs:element>
</xs:schema>

我在氧气中尝试了一下,文档有效。

这是我使用的两个文件:

XSD文件:

<?xml version="1.0" encoding="ISO-8859-1" ?> 
<Config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation='schema.xsd'>
    <Test Script="final.sh" />
</Config>

XML文件:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">   
    <xs:element name="Config">
        <xs:complexType>
            <xs:all> 
                <xs:element name="Test" minOccurs="0">
                    <xs:complexType>
                        <xs:attribute name="Script" type="xs:string" use="required" />          
                    </xs:complexType>
                </xs:element>
            </xs:all>
        </xs:complexType>
    </xs:element>
</xs:schema>

确保将XSD模式连接到XML文件,然后可以。

提供的实例文档对提供的模式有效,因此这里发生了一些奇怪的事情。

错误消息似乎表明您实际上正在验证

的架构
targetNamespace="http://www.w3.org/2001/XMLSchema"

这对它说是很奇怪的。

恐怕您在对您的问题的其他回答中得到了很多非常糟糕的建议。

缺少根名称空间,将其添加到

相关内容

  • 没有找到相关文章

最新更新