Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an xsd schema for xsd schemas? [duplicate]

Tags:

xml

xsd

I frequently use xsd schema files in my work, and I got to wondering: Is it possible to write an xsd schema file for the xsd schema language? It seems like an obvious way to document the schema language, and I would think it would be one of the first things its developers would try. However, I've been unable to find such a file with obvious search terms. If it's not possible, why not? If it is possible, has anyone done it and is there a place I could download such a file?

Notes:

  1. Wikipedia suggests the xsd schema language is "not 100% self describing" because "content and attribute declarations cannot depend on attributes or element context". If this is so, can you provide an example of a feature of xsd that requires such context and therefore can't be represented?

  2. This question isn't purely academic. I may need to write a program that processes xsd schema files in the near future, and generating source code from an xsd (with a tool such as generateDS) would be an easy place to start.

like image 873
jcrudy Avatar asked Jul 18 '13 22:07

jcrudy


People also ask

What is the purpose of schema select one to avoid duplication in XML?

The purpose of an XSD schema is to define and describe a class of XML documents by using schema components to constrain and document the meaning, usage and relationships of their constituent parts: datatypes, elements and their content and attributes and their values.

Is XSD and schema same?

An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD).

How do I add XSD to XSD?

If you are giving Absolute path, then you need to write <xs:include schemaLocation="file:D:/workspace/Test/res/header. xsd" /> Remember to add the 'file:' before adding the location.

Can XSD have multiple root elements?

While a properly formed XML file can only have a single root element, an XSD or DTD file can contain multiple roots.


2 Answers

Indeed, there is an XML schema for the XSD language, which exists from the very start (as its URL suggests):

http://www.w3.org/2001/XMLSchema.xsd

and here's the XSD file for its most recent version -- W3C XML Schema Definition Language (XSD) 1.1:

http://www.w3.org/2012/04/XMLSchema.xsd

In fact, those XSD files (at least the first one) are heavily used now by various software working with XML schemas. Otherwise, I think, it would be complete absurd to have an XML schema language expressed in the form XML and not to have an XSD description of it!


For that matter, there is even an XML-based programming language called XSLT (very important in XML technologies), and, you guess, there is an XML schema for it too:

http://www.w3.org/2007/schema-for-xslt20.xsd

like image 89
ColdFusion Avatar answered Sep 24 '22 23:09

ColdFusion


The Wikipedia statement that XSD is "not 100% self describing" is correct in the sense that not every document conforming to the schema-for-schema-documents (S4SD) is capable of producing a valid schema. One reason for this is that there are constraints that cannot be expressed in XSD (for example, that the content of xpath attributes should be syntactically-valid XPath expressions); another is that XSD can only express constraints on a single document, whereas for a schema to be valid, there are consistency constraints that apply across documents.

If the S4SD took full advantage of XSD 1.1 capabilities then it would be possible to get much closer to 100% coverage of all the "XML representation" rules; I was hoping to attempt this but it never got done. There would still be a few gaps.

Your plan to write software that processes schema documents is one you should think about carefully. It's not easy to extract information from raw schema documents because there are so many different ways a schema author can express the same thing. The alternative is to work with an API that offers access to the "schema components" (such as element declarations and type definitions) that a schema processor creates from the raw input documents. Several schema processors offer such an API. Saxon-EE delivers the schema components in an XML representation called SCM, which is much easier to process than the raw XSD documents.

like image 31
Michael Kay Avatar answered Sep 23 '22 23:09

Michael Kay