对元素的引用将(不需要的)命名空间添加到目标 xml

Reference to elements adds (unwanted) namespace to target xml

我的总体目标是将一个大的 xsd 分解成几个小的 xsd,其中一个特别包含我想在其他 xsd 中重用的元素和复杂类型.假设类型 xsd 被称为 "types.xsd" 而另一个 xsd 被称为 "request.xsd"

也就是说,我将一个中心 ID "evalancheId" 声明为一个元素并尝试引用(使用 ref)它们。但是,生成的 XML 为引用的元素附带了不需要的名称空间前缀 "ns:evalancheId"。

types.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://hansgrohe.com/pi/PA/C4C/Contact/10" 
xmlns="http://hansgrohe.com/pi/PA/C4C/Contact/10">

<xsd:element name="evalancheId" type="xsd:int"/>

<xsd:complexType name="contactComplexType">
    <xsd:sequence>
        <xsd:element minOccurs="0" maxOccurs="1" name="givenName">
            <xsd:simpleType>
                <xsd:restriction base="xsd:string">
                    <xsd:minLength value="1"/>
                    <xsd:maxLength value="40"/>
                </xsd:restriction>
            </xsd:simpleType>
        </xsd:element>
        <!-- ... -->
    </xsd:sequence>
</xsd:complexType>

request.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://hansgrohe.com/pi/PA/C4C/Contact/10" 
xmlns="http://hansgrohe.com/pi/PA/C4C/Contact/10">
<xsd:include schemaLocation="types.xsd"/>
<xsd:element name="updateContactReq" type="contactUpgradeComplexType"/>
<xsd:complexType name="contactUpgradeComplexType">
    <xsd:complexContent>
        <xsd:extension base="contactComplexType">
            <xsd:sequence>
                <xsd:element ref="evalancheId" minOccurs="1" maxOccurs="1"/>
            </xsd:sequence>
        </xsd:extension>
    </xsd:complexContent>
</xsd:complexType>

result.xml

<ns:updateContactReq xmlns:ns="http://hansgrohe.com/pi/PA/C4C/Contact/10">
    <givenName>Jay</givenName>
    <ns:evalancheId>0815</ns:evalancheId>
</ns:updateContactReq>

actually_wanted.xml

<ns:updateContactReq xmlns:ns="http://hansgrohe.com/pi/PA/C4C/Contact/10">
    <givenName>Jay</givenName>
    <evalancheId>0815</evalancheId>
</ns:updateContactReq>

问题

  1. 我怎样才能摆脱 "ns:evalancheId" 中的名称空间并重新使用 evalancheId 元素

非常感谢和亲切的问候 岑瑟

我不相信你可以。 including/importing XSD 只有全局元素可见以供重用。但是全局元素总是在它们自己的目标命名空间中 XSD。 您可以将 elementFormDefault 设置为 'unqualified' 并将元素声明为本地(即非全局)元素定义。但这会使您 objective 将元素包含在单独的 XSD 中失败。 我认为对您来说最好的解决方案是在单独的 XSD 中定义 types 但在您的 main XSD。这样,元素声明可以是本地的,而复杂类型是在单独的 XSD.

中定义的