开发者

Difference/similarities between xsd:any and xsd:anyType

I am reading about XML, XML-Schema, DTD and I don't really understand the difference between xsd:any and 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)

TIA


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).

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:

<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.

Also take a look at the XML Schema.


The mailing list post linked in dogbane's answer wasn't clear to me until I created the following example:

With anyType schema:

<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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜