Here is another schema file, octaves.xsd which uses midi.xsd to help define the layout to be enforced on an XML file containing data about octaves:<?xml version="1.0" encoding="utf-8"?><xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:include schemaLocation="midi.xsd"/> <xs:element name="octaves"> <xs:complexType> <xs:sequence> <xs:element name="octave"> <xs:complexType> <xs:sequence> <xs:element name="name" type="xs:string" /> <xs:element name="midi"> <xs:complexType> <xs:sequence> <xs:element name="value" type="xs:integer" /> <xs:element name="from" type="note" /> <xs:element name="to" type="note" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> <xs:attribute name="index" type="xs:integer" /> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element></xs:schema>这很好,并且完全按照您的预期工作,除了我有另一个要求:我希望 note 在它自己的命名空间中,midi,这样This is fine, and works exactly as you would expect it to, except that I have another requirement: I want note to be in its own namespace, midi, so that<xs:element name="from" type="note" />变成<xs:element name="from" type="midi:note" />尽我所能,我无法让它工作.我的尝试包括在不同地方使用 targetNamespace 属性、import 元素以及自由使用 xmlns:midi="...",但无济于事.我会在这里发布这些尝试之一,如果它不是那么令人畏惧的话.Try as I might, I cannot get this to work. My attempts have included use of the targetNamespace attribute in various places, the import element, and liberal use of xmlns:midi="...", but to no avail. I'd post one of these attempts here, were it not so cringe-worthy.有好心人能指出我正确的方向吗?我很确定问题在于midi.xsd 是本地文件;它从来没有,也永远不会,托管在网络服务器上.Could some kind soul point me in the right direction? I'm pretty sure the problem is to do with the fact that midi.xsd is a local file; it has never been, and never will be, hosted on a web server.推荐答案将 midi.xsd 更改为:<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetnamespace="/my/midi/namespace">然后把octaves.xsd改成:<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:midi="/my/midi/namespace"> <xs:import namespace="/my/midi/namespace" schemaLocation="midi.xsd"/> ... <xs:element name="from" type="midi:note" />注意使用 xs:import 而不是 两者是非常不同的——你使用 import 来引入在其他命名空间中,并且 include 用于将其他架构文件内联包含到 current 命名空间中.Note the use of xs:import rather than <xs:include> The two are very different - you use import for bringing in other namespaces, and include for inline inclusion of other schema files into the current namespace.还要注意 /my/midi/namespace 可以是你想要的任何东西,它是一个任意标识符.Note also that /my/midi/namespace can be anything you want, it's an arbitrary identifier.我很确定问题与 midi.xsd 是本地文件这一事实有关 I'm pretty sure the problem is to do with the fact that midi.xsd is a local file不,不相关. 这篇关于包括/导入具有命名空间的本地模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 19:59