cvc-elt.1:找不到元素'MyElement'的声明 [英] cvc-elt.1: Cannot find the declaration of element 'MyElement'

查看:539
本文介绍了cvc-elt.1:找不到元素'MyElement'的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用xsd验证一个非常简单的xml,但是由于某种原因,我收到了此错误. 如果有人能解释我的原因,我将不胜感激.

I'm trying to validate a really simple xml using xsd, but for some reason I get this error. I'll really appreciate if someone can explain me why.

XML文件

<?xml version="1.0" encoding="utf-8"?> 
<MyElement>A</MyElement>

XSD文件

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
        targetNamespace="http://www.example.org/Test"
        xmlns:tns="http://www.example.org/Test"
        elementFormDefault="qualified">

    <simpleType name="MyType">
        <restriction base="string"></restriction>
    </simpleType>

    <element name="MyElement" type="tns:MyType"></element>
</schema>

推荐答案

您的架构用于其目标名称空间http://www.example.org/Test,因此它在该目标名称空间http://www.example.org/Test中定义了名称为MyElement的元素.但是,您的实例文档在没有名称空间中具有一个名为MyElement的元素.这就是为什么验证解析器会告诉您找不到该元素的声明的原因,没有为没有命名空间的元素提供架构.

Your schema is for its target namespace http://www.example.org/Test so it defines an element with name MyElement in that target namespace http://www.example.org/Test. Your instance document however has an element with name MyElement in no namespace. That is why the validating parser tells you it can't find a declaration for that element, you haven't provided a schema for elements in no namespace.

您要么需要更改架构以完全不使用目标名称空间,要么需要更改实例以使用例如<MyElement xmlns="http://www.example.org/Test">A</MyElement>.

You either need to change the schema to not use a target namespace at all or you need to change the instance to use e.g. <MyElement xmlns="http://www.example.org/Test">A</MyElement>.

这篇关于cvc-elt.1:找不到元素'MyElement'的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆