I am reading about XML, XML-Schema, DTD and I don't really understand the difference between xsd:any and xsd:anyType.
我正在阅读关于XML、XML- schema、DTD的文章,我并没有真正理解xsd:any和xsd:anyType之间的区别。
Can someone explain this to me or point to some good article? (please don't link to the XML-Schema specifications - I read that and I'm more confused)
有人能给我解释一下吗?(请不要链接到xml模式规范——我读了这个,我更糊涂了)
TIA
蒂雅
2 个解决方案
#1
27
This post explains it nicely. I quote:
这篇文章很好地解释了这一点。我引用:
xsd:anyType is a type, like xsd:integer (though xsd:anyType is special in that it can act as a simple or complex type, and it places essentially no restrictions on the tree that it validates -- think of it loosely as the Schema language's analog of java.lang.Object).
任何类型都是一种类型,如xsd:integer(尽管xsd:anyType是特殊的,因为它可以作为一个简单或复杂的类型,并且它对它所验证的树基本上没有限制——可以把它松散地看作是模式语言的java.lang.Object的模拟)。
A sample use would be:
样本的使用情况如下:
<xsd:element name="e" type="xsd:anyType"/>
This would mean that elements named
<e>
can have any content, any attributes, etc.这意味着命名为
的元素可以有任何内容、任何属性等等。 xs:any is a wildcard, usable as a term in a content model. For example:
xs:any是通配符,可用作内容模型中的术语。例如:
<xsd:complexType name="T">
<xsd:sequence>
<xsd:element ref="A"/>
<xsd:any />
<xsd:element ref="C"/>
</xsd:sequence>
</xsd:complexType>
Elements of type T must have content
<A/><???/><C/>
, where<???>
can be any named element. Now, if you look really closely there is an approximation to the definition of xsd:anyType given for reference in the Recommendation, and it uses an xsd:any wildcard as the means of saying that it allows any elements.类型T的元素必须具有内容 < C / >,< ? ? ?>可以是任何命名元素。现在,如果您仔细观察,就会发现xsd:any类型的定义有一个近似值,它使用xsd:any通配符来表示它允许任何元素。
Also take a look at the XML Schema.
还要看一下XML模式。
#2
25
The mailing list post linked in dogbane's answer wasn't clear to me until I created the following example:
在我创建了以下示例之前,我不太清楚dogbane答案中链接的邮件列表。
With anyType schema:
anyType模式:
<xsd:complexType name="Outer">
<xsd:element name="e" type="xsd:anyType" />
</xsd:complexType>
Which allows this format:
它允许这种格式:
<Outer>
<e> // must be called "e"
// but anything can go inside
</e>
</Outer>
And with any schema:
和任何模式:
<xsd:complexType name="Outer">
<xsd:any />
</xsd:complexType>
Which allows this format:
它允许这种格式:
<Outer>
//anything can go inside
</Outer>
So anyType is a type, and any is an element
任何类型都是类型,任何类型都是元素
#1
27
This post explains it nicely. I quote:
这篇文章很好地解释了这一点。我引用:
xsd:anyType is a type, like xsd:integer (though xsd:anyType is special in that it can act as a simple or complex type, and it places essentially no restrictions on the tree that it validates -- think of it loosely as the Schema language's analog of java.lang.Object).
任何类型都是一种类型,如xsd:integer(尽管xsd:anyType是特殊的,因为它可以作为一个简单或复杂的类型,并且它对它所验证的树基本上没有限制——可以把它松散地看作是模式语言的java.lang.Object的模拟)。
A sample use would be:
样本的使用情况如下:
<xsd:element name="e" type="xsd:anyType"/>
This would mean that elements named
<e>
can have any content, any attributes, etc.这意味着命名为
的元素可以有任何内容、任何属性等等。 xs:any is a wildcard, usable as a term in a content model. For example:
xs:any是通配符,可用作内容模型中的术语。例如:
<xsd:complexType name="T">
<xsd:sequence>
<xsd:element ref="A"/>
<xsd:any />
<xsd:element ref="C"/>
</xsd:sequence>
</xsd:complexType>
Elements of type T must have content
<A/><???/><C/>
, where<???>
can be any named element. Now, if you look really closely there is an approximation to the definition of xsd:anyType given for reference in the Recommendation, and it uses an xsd:any wildcard as the means of saying that it allows any elements.类型T的元素必须具有内容 < C / >,< ? ? ?>可以是任何命名元素。现在,如果您仔细观察,就会发现xsd:any类型的定义有一个近似值,它使用xsd:any通配符来表示它允许任何元素。
Also take a look at the XML Schema.
还要看一下XML模式。
#2
25
The mailing list post linked in dogbane's answer wasn't clear to me until I created the following example:
在我创建了以下示例之前,我不太清楚dogbane答案中链接的邮件列表。
With anyType schema:
anyType模式:
<xsd:complexType name="Outer">
<xsd:element name="e" type="xsd:anyType" />
</xsd:complexType>
Which allows this format:
它允许这种格式:
<Outer>
<e> // must be called "e"
// but anything can go inside
</e>
</Outer>
And with any schema:
和任何模式:
<xsd:complexType name="Outer">
<xsd:any />
</xsd:complexType>
Which allows this format:
它允许这种格式:
<Outer>
//anything can go inside
</Outer>
So anyType is a type, and any is an element
任何类型都是类型,任何类型都是元素