无法编译 W3C 提供的 XSD 架构;无法解析“id"? [英] can't compile a W3C-provided XSD schema; can't resolve "id"?

查看:15
本文介绍了无法编译 W3C 提供的 XSD 架构;无法解析“id"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 XML 模式并尝试生成使用它的简单有效文档.

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

架构 XSD 由 W3C 提供,所以我无法想象它实际上有什么问题.但是命令行上的 xmllint 以及任意数量的免费在线验证器都抱怨实际的 XSD(不是我的测试文档):

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.

请注意,它无法解析 id 类型/名称,这是基本的 XML 内容.我不是 XML 大师,所以我可能在这里遗漏了一些关于命名空间/链接的明显信息.这不是我的测试文档的问题,因为即使是一个微不足道的测试文档在 XSD 编译位中也会失败.

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.

这是 XSD 文件.这是一个简单的测试文档:

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>

但尽我所能,我无法让 xmllint 或任何在线验证器通过 XSD 解析/编译阶段,因为 XML id 类型在某种程度上是不稳定的.

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.

我对 XML 的理解在这里不正确吗?我在问 SO(与另一个站点),因为最终这是关于理解 XML 规范和依赖关系来编写和验证文档.我欢迎能做正确事情的代码片段,无论正确的事情是什么.

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.

想法?谢谢.

推荐答案

您指向的架构包含一个对众所周知的 XML 架构的导入语句.

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" />

前者不为您提供 schemaLocation 属性.

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

如果您使用 http://www.w3.org/2001/xml.xsd URL 并粘贴到您的浏览器中,一段时间后(或不,取决于,这些链接被限制) 您应该会看到 xml.xsd - 您的案例中缺少的部分;如果您看到 HTML 而不是纯 XML,请切换到源代码视图以查看它,这意味着 ../2008/09/xsd.xsl 样式表已由您的浏览器自动应用.

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.

我确信,如果您现在修改第一个导入以包含 schemaLocation 属性,大多数验证器现在应该可以工作了.

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

这个导入很可能是悬而未决",作为一种安全措施,以确保人们不会因为被认为是众所周知的 XSD 的内容而一遍又一遍地访问 W3C 站点.期望(至少从我过去看到的情况来看)是 XSD 处理器能够自动将这些众所周知的命名空间引用解析为这些 XSD 的某种本地/嵌入式副本.显然,您尝试过的处理器默认情况下不会这样做.

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(我与它相关)确实解决了它,所以如果你在本地下载这两个 XSD 然后按原样加载它们,每个验证都很好.

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.

如果您不想修改 XSD - 例如当您真正想要从远程 URL 加载 XSD 时,解决方案是向您的 XSD 处理器提供某种目录信息以帮助它解析 xml.xsd.对于 xmllint,请使用 --catalogs 选项.我建议使用 xml.xsd 的本地副本.浏览您系统上可能已有的目录(如果设置了 $SGML_CATALOG_FILES,否则为/etc/xml/catalog),也许您可​​以使用现有的目录.

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.

这篇关于无法编译 W3C 提供的 XSD 架构;无法解析“id"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆