XSD验证错误:元素'{http://www.example.com}作用域':不应使用此元素.预期的是(范围) [英] XSD validation error: Element '{http://www.example.com}Scope': This element is not expected. Expected is ( Scope )

查看:106
本文介绍了XSD验证错误:元素'{http://www.example.com}作用域':不应使用此元素.预期的是(范围)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了以下XSD(使用Eclipse):

I created the following XSD (with Eclipse):

  <?xml version="1.0" encoding="UTF-8"?>
  <schema targetNamespace="http://www.example.com" xmlns="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.example.com">
    <element name="Make">
      <complexType>
        <sequence>
          <element name="Scope"></element>
        </sequence>
      </complexType>
    </element>
  </schema>

并使用此简单的XML进行验证

and validating with this simple XML

  <?xml version="1.0"?>
  <Make xmlns="http://www.example.com">
    <Scope>
    </Scope>
  </Make>

给予:

  xmllint.exe --noout --schema sources.xsd sources.xml
  sources.xml:3: element Scope: Schemas validity error : Element '{http://www.example.com}Scope': This element is not expected. Expected is ( Scope ).
  sources.xml fails to validate

我认为这必须是正确的:XML文件位于名称空间 http:/中/www.example.com (验证者也说).

In my opinion, this must be correct: the XML file is in the namespace http://www.example.com (what also the validator says).

对于XSD,我将默认名称空间设置为XSD模式(这是Eclipse所做的,因此它应该是正确的!),并且给出正确的targetNamespace.我也尝试使用

And for the XSD I set the default namespace to the XSD schema (this is what Eclipse does, so it should be correct!) and I give the correct targetNamespace. I also tried to use

<element name="tnd:Scope" />

但是,这也不起作用.

这是xmllint中的bug还是问题在哪里?

Is this a bug in xmllint or where is the problem?

问候 divB

推荐答案

@dbasemans 答案的替代方法是将elementFormDefault指定为限定:

An alternative to @dbasemans answer would be to specify the elementFormDefault as qualified:

 <schema targetNamespace="http://www.example.com"
     xmlns="http://www.w3.org/2001/XMLSchema"
     xmlns:tns="http://www.example.com"
     elementFormDefault="qualified">

在模式名称空间中使用xsdxs前缀可能被认为是常见的,因此可能希望根据 dbaseman 的建议选择修改您的模式.

Using the xsd or xs prefix for your schema namespace could be considered as common, so may want to choose to modify your schema as suggested by dbaseman.

这篇关于XSD验证错误:元素'{http://www.example.com}作用域':不应使用此元素.预期的是(范围)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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