can't compile a W3C-provided XSD schema; can't resolve “id”?

筅森魡賤 提交于 2020-01-04 04:48:06

问题


I'm playing around with an XML schema and trying to produce a simple valid document that uses it.

The schema XSD is provided by the W3C, so I can't imagine anything's actually wrong with it. But xmllint on the command line as well as any number of freebie online validators complain about the actual XSD (not my test document) with:

The QName value '{http://www.w3.org/XML/1998/namespace}id' does not resolve to a(n) attribute declaration.

Note that it can't resolve the id type/name, which is base XML stuff. I'm not an XML master, so I may be missing something obvious about the namespace/linkage here. This isn't a problem with my test document, because even a trivial test document fails in the XSD compile bit.

Here's the XSD file. Here is a trivial test document:

 <?xml version="1.0" encoding="UTF-8"?>
 <ink xmlns="http://www.w3.org/2003/InkML" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://www.w3.org/TR/2011/REC-InkML-20110920/inkml.xsd">
 </ink>

But try as I might, I can't get xmllint or any online validators to even get past the XSD parse/compile phase, because the XML id type is somehow wonky.

Is my understanding of XML incorrect here? I'm asking on SO (vs another site) because ultimately this is about understanding the XML specification and dependencies to write and validate a document. I'd welcome code snippets that do the right thing, whatever the right thing is.

Thoughts? Thanks.


回答1:


The schema you pointed at contains an import statement to a well known XML Schema.

<xsd:import namespace="http://www.w3.org/XML/1998/namespace" id="xml" />
<!-- schemaLocation="http://www.w3.org/2001/xml.xsd" -->

As you can see, unlike this other one below...

<xsd:import namespace="http://www.w3.org/1998/Math/MathML" schemaLocation="inkml-mathml2-subset.xsd" id="mathml" />

the former doesn't provide you with a schemaLocation attribute.

If you take the http://www.w3.org/2001/xml.xsd URL and paste into your browser, after a while (or not, it depends, these links are throttled) you should see the xml.xsd - the missing piece in your case; if you see HTML instead of plain XML, switch to source view to see it, it means the ../2008/09/xsd.xsl stylesheet was automatically applied by your browser.

I am sure that if you now modify the first import to include the schemaLocation attribute, most of the validators should now work.

This import is left "dangling" most likely as a safe measure to ensure that people don't hit the W3C site over and over for what is considered a well known XSD. The expectation (at least from what I am used to see) is for XSD processors to automatically resolve these kind of well-known namespace references to some sort of local/embedded copies of those XSDs. Obviously, the processors you've tried don't do it by default.

QTAssistant (I am associated with it) does resolve it, so if you download those two XSDs locally and then load them as-is, each one validates just fine.

If you don't want to modify the XSD - for e.g. when you actually want to load the XSD from the remote URL, then the solution is to provide some sort of catalog information to your XSD processor to help it resolve xml.xsd. For xmllint, use the --catalogs option. I recommend to use a local copy of the xml.xsd. Go through the catalogs you might already have on your system ($SGML_CATALOG_FILES if set, otherwise /etc/xml/catalog) , maybe you can use an existing one already.



来源:https://stackoverflow.com/questions/15373503/cant-compile-a-w3c-provided-xsd-schema-cant-resolve-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!