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

查看:19
本文介绍了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 中的 code>MyElement.但是,您的实例文档在 no namespace 中有一个名为 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天全站免登陆