XSD 中的空元素是否有效? [英] Is an empty element valid in XSD?

查看:35
本文介绍了XSD 中的空元素是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继续我今天的XSD问题:>

在 XSD 文档中,如下:

<元素/>

一个有效的构造?也就是说,它是一个没有名称、类型或任何东西的元素.完全匿名.

如果这是一个有效的 XSD,那是什么意思?这样的元素将如何出现在 XML 中?

解决方案

取决于放置的位置.

xs:appInfoxs:documentation(以及其他一些结构)中,任何东西都可能是有效的.

接下来这个元素:

<元素/>

不指定命名空间.因此,它要么位于错误的命名空间中,要么在上下文中的某处存在 xmlns=http://www.w3.org/2001/XMLSchema".

假设后者,这可能是全局 (topLevelElement) 或本地 (localElement) 元素定义.

在两种情况下都无效:

  • 全局元素必须具有 name 属性.
  • 本地元素必须具有 nameref 属性.我认为仅根据架构的 schema 它可能在语法上是有效的,但是有是规范中的限制:
<块引用>

2 如果项目的父项不是 ,则以下所有条件都必须为真:

2.1 ref 或 name 必须存在其中之一,但不能同时存在.

Continuing my XSD questions for today:

In an XSD document, is the following:

<element />

a valid construct? That is, it's an element which does not have a name, type, anything. Totally anonymous.

And if this is a valid XSD, what does that mean? How would such an element appear in the XML?

解决方案

Depends on where it is placed.

In xs:appInfo or xs:documentation (and few other constructs) anything may be valid.

Next this element:

<element />

Does not specify the namespace. So it is either in a wrong namespace or there's a xmlns="http://www.w3.org/2001/XMLSchema" somewhere in the context.

Assuming the latter this may be a global (topLevelElement) or a local (localElement) element definition.

It is invalid in both cases:

  • Global element must have a name attribute.
  • Local element must have have a name or a ref attribute. I think that just according the schema of the schema it might be syntactically valid, but there are restrictions in the specification:

2 If the item's parent is not , then all of the following must be true:

2.1 One of ref or name must be present, but not both.

这篇关于XSD 中的空元素是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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