Search code examples
xmlxsdxml-parsingschemaxsd-1.1

Why does the official XMLSchema.xsd fail to parse?


As an experiment, I want to create an XSD to Object Pascal. I am writing it in C# because I am more comfortable with it and it has a lot more tooling available for it.

I figured a good place to start is by using XSD.EXE to generate the equivalent Object Pascal data types from the official XSD of XMLSchema:

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

I tried XSD.EXE as well as a bunch of other XSD to c# parsers. I made no changes to the XSD. None of the generators couldn't parse the XMLSchema.xsd.

Why is it failing? What am I doing wrong?

joe$ wget https://www.w3.org/2012/04/XMLSchema.xsd
--2022-07-10 13:24:01--  https://www.w3.org/2012/04/XMLSchema.xsd
Resolving www.w3.org (www.w3.org)... 128.30.52.100
Connecting to www.w3.org (www.w3.org)|128.30.52.100|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 71264 (70K) [application/xml]
Saving to: ‘XMLSchema.xsd’

XMLSchema.xsd                    100%[=======================================================>]  69.59K  --.-KB/s    in 0.08s   

2022-07-10 13:24:01 (911 KB/s) - ‘XMLSchema.xsd’ saved [71264/71264]

joe$ xsd XMLSchema.xsd /c
Error: Invalid particle derivation by restriction. Invalid particle derivation by restriction.
Written file ./XMLSchema.cs

Solution

  • The schema document at that location validates OK with the Saxon schema validator; I don't think there is anything wrong with it.

    The error message seems very strange, because there is no XML declaration at line 30.

    It feels to me as if you're not processing the document you think you are, but that's only because I can't think of any other explanation.

    The schema you refer to is the schema for XSD 1.1, which the Microsoft schema processor doesn't support; but that doesn't account for the strange error message.