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
The xsd:anyType is the base data type from which all simple and complex data types are derived. It does not restrict the data content.
Differences: XSD is based and written on XML. XSD defines elements and structures that can appear in the document, while XML does not. XSD ensures that the data is properly interpreted, while XML does not.
For brevity, the text and examples in this specification use the prefix xs: to stand for this namespace; in practice, any prefix can be used. in the end xs or xsd are only prefixes. XSD is used for example more by Microsoft schemas. The important is how you declare the namespace.
XML Schema is commonly known as XML Schema Definition (XSD). It is used to describe and validate the structure and the content of XML data. XML schema defines the elements, attributes and data types. Schema element supports Namespaces.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With