Import two XSDs from namespace 2 with non-overlapping definitions into an XSD from namespace 1

I refer to the question ‘Import same Namespace from different xsd’ with the difference that the definitions in my two imported XSDs do not overlap.

I need to import two XSDs (kd1.xsd and kd2.xsd) with identical namespace and non-overlapping element or type definitions into a parent XSD (main.xsd) with its own namespace. The main.xsd is read in by applications, class generators and validators, for example.

The XSDs to be imported use both definitions from another XSD (other.xsd), which is in the same namespace as the main.xsd. However, I think this has nothing to do with the problem.

My problem is that the definitions of the second imported kd2.xsd are apparently not visible.

main.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.anbieter.de/xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:kun="http://www.anbieter.de/xsd"
    targetNamespace="http://www.anbieter.de/xsd"
    xsi:schemaLocation="http://www.anbieter.de/xsd other.xsd
        http://www.kunde.de/xsd kd1.xsd
        http://www.kunde.de/xsd kd2.xsd">

    <xs:include schemaLocation="other.xsd"/>
    <xs:import namespace="http://www.kunde.de/xsd" schemaLocation="kd1.xsd"/>
    <xs:import namespace="http://www.kunde.de/xsd" schemaLocation="kd2.xsd"/>
</xs:schema>

kd1.xsd, kd2.xsd

<?xml version="1.0"?>
<xs:schema xmlns="http://www.kunde.de/xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:kun="http://www.kunde.de/xsd"
    targetNamespace="http://www.kunde.de/xsd"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="element1">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="sub11" type="xs:string"/>
                <xs:element name="sub12" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

<?xml version="1.0"?>
<xs:schema xmlns="http://www.kunde.de/xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:kun="http://www.kunde.de/xsd"
    targetNamespace="http://www.kunde.de/xsd"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="element2">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="sub21" type="xs:string"/>
                <xs:element name="sub22" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

other.xsd:

<?xml version="1.0"?>
<xs:schema xmlns="http://www.w3.org/2001/XMLSchema"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.anbieter.de/xsd"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:element name="otherelement">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="foo" type="xs:string"/>
                <xs:element name="bar" type="xs:string"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

For example, a validator that pulls in the main.xsd sees the definition of element1 in kd1.xsd but not that of element2 in kd2.xsd (‘Can’t find the declaration of …’).

<?xml version="1.0" encoding="UTF-8"?>
<kun:element1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.anbieter.de/xsd"
 xmlns:kun="http://www.kunde.de/xsd"
 xsi:schemaLocation="http://www.kunde.de/xsd file:/C:/Users/uheyder/Downloads/main.xsd">
    <kun:sub11>sub110</kun:sub11>
    <kun:sub12>sub120</kun:sub12>
</kun:element1>

is ok but

<?xml version="1.0" encoding="UTF-8"?>
<kun:element2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xsd="http://www.anbieter.de/xsd"
 xmlns:kun="http://www.kunde.de/xsd"
 xsi:schemaLocation="http://www.kunde.de/xsd file:/C:/Users/uheyder/Downloads/main.xsd">
    <kun:sub21>sub110</kun:sub21>
    <kun:sub22>sub120</kun:sub22>
</kun:element2>

is not. If I swap the import lines, it is the other way around.

Similarly, I can generate examples of element1 with the XML example generator of a used XML development tool, but not of element2.

Question 1:
Is it generally not allowed and possible to import two XSDs with identical namespaces and non-overlapping element or type definitions directly into a parent XSD with its own namespace, so that the parent XSD alone can be worked with?

Question 2:
If there are options, how do I need to structure my XSDs differently or change content?

Constraints are that

  • the namespaces of kd1.xsd and kd2.xsd are identical

  • this differs from the namespace of main.xsd and

  • only the main.xsd is used as anchor

As an emergency solution, I would import an additional auxiliary XSD in the namespace of both kd1.xsd and kd2.xsd, which in turn includes kd1.xsd and kd2.xsd. However, I find this solution cumbersome and less transparent.

Note: The example is very simplified, but leads to the same problems as the actual XSD model.

Thanks, Ulf

New contributor

Ulf is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật