简体   繁体   English

我可以将XML架构导入另一个架构的targetNamespace吗?

[英]Can I Import XML schema into the targetNamespace of another schema?

I have three schemas: slideshow, problems, and widgets. 我有三个模式:幻灯片,问题和小部件。 The slideshow and problems schemas import widgets. 幻灯片和问题模式导入小部件。 However, the namespace of slideshow, problems and widgets are different. 但是,幻灯片放映,问题和小部件的命名空间是不同的。 I've defined my imports like the following: 我已经定义了我的导入,如下所示:

 <?xml version="1.0" encoding="UTF-8"?>
 <xs:schema targetNamespace="http://www.mydomain.com/slideshow"
       xmlns="http://www.mydomain.com/slideshow"
       xmlns:xs="http://www.w3.org/2001/XMLSchema"
       xmlns:wd="http://www.mydomain.com/widgets"
       elementFormDefault="qualified">

    <xs:import namespace="http://www.mydomain.com/widgets" schemaLocation="./widgets-v1.0.xsd"/>

 </xs:schema>

However, this requires I use fully qualified names for elements from the widgets schema (eg wd:someElement). 但是,这需要我使用小部件架构中的元素的完全限定名称(例如wd:someElement)。 I'd really like to import the definitions from widgets into the slideshow and problem namespace so you don't have to use wd:someElement to refer to someElement. 我真的想将小部件中的定义导入到幻灯片和问题命名空间中,因此您不必使用wd:someElement来引用someElement。 As if they were defined directly in those respective schemas. 好像它们是直接在那些相应的模式中定义的。

I've tried include, but that requires widgets be the same namespace of the importing document with problems and widgets being different so that option seems like it doesn't work. 我已经尝试过include,但是这需要小部件与导入文档的命名空间相同,问题和小部件不同,所以选项似乎不起作用。

How can I do this? 我怎样才能做到这一点?

If you want the elements in the three schema documents to be in different namespaces, then you will have to use QNames to reference them. 如果您希望三个模式文档中的元素位于不同的名称空间中,则必须使用QNames来引用它们。

Of course you could change the design so they don't use different namespaces, but you haven't suggested that's what you want to do. 当然,您可以更改设计,以便它们不使用不同的命名空间,但您没有建议这是您想要做的。

The only way to do it is to employ the reuse of XSD content through the so called chameleon pattern . 唯一的方法是通过所谓的变色龙模式来重用XSD内容。 This would allow you, in terms of XML namespaces, to "white-label" whatever components you need. 根据XML命名空间,这将允许您“白标”所需的任何组件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM