javaxmlxsdxsd-validationxml-validation

Configure an XSD to consist of multiple xs:schemas?


I have an XSD file in which I would like to place several diagrams, with a description of the services. When adding

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified"
            attributeFormDefault="qualified"
            targetNamespace="[target1]"
            xmlns:tns="[target1]">

</xsd:schema>

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified"
            attributeFormDefault="qualified"
            targetNamespace="[target2]"
            xmlns:tns="[target2]">
</xsd:schema>

I get error: "Multiple root tags"

If I write like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified"
            attributeFormDefault="qualified"
            targetNamespace="[target1]"
            xmlns:tns="[target1]">
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified"
            attributeFormDefault="qualified"
            targetNamespace="[target2]"
            xmlns:tns="[target2]">
    </xsd:schema>
</xsd:schema>

I get error:

Invalid content was found starting with element '{"http://www.w3.org/2001/XMLSchema":schema}'. One of '{"http://www.w3.org/2001/XMLSchema":simpleType, "http://www.w3.org/2001/XMLSchema":complexType, "http://www.w3.org/2001/XMLSchema":group, "http://www.w3.org/2001/XMLSchema":attributeGroup, "http://www.w3.org/2001/XMLSchema":element, "http://www.w3.org/2001/XMLSchema":attribute, "http://www.w3.org/2001/XMLSchema":notation, "http://www.w3.org/2001/XMLSchema":annotation}' is expected.

Is it possible to configure an XSD file to consist of multiple schemas xsd:schema?


Solution

  • XSDs cannot be composed by embedding xsd:schema elements like that.

    To incorporate multiple XSDs with distinct targetNamespaces, use xsd:import.

    See also