[xsd-users] Multiple imports - (Re: Different C++ namespace for included schema)

Matt Burnham mburnham at gblsys.com
Mon Sep 22 14:29:09 EDT 2008


Hi Boris,

I've converted over to using namespaces in the schemas and using import 
instead of include, but I now have a problem with multiple imports.  If 
I have 2 schemas (same namespace) and import them both into a third 
(different namespace), then when I reference them, I get an error of 
"Type not found" for the second one imported.

test1.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:foo="http://www.codesynthesis.com/foo"
            targetNamespace="http://www.codesynthesis.com/foo">
    <xsd:element name="type1" type="foo:type1"/>
    <xsd:complexType name="type1">
        <xsd:attribute name="value1" type="xsd:int" use="required"/>
    </xsd:complexType>
</xsd:schema>

test2.xsd:
?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:foo="http://www.codesynthesis.com/foo"
            targetNamespace="http://www.codesynthesis.com/foo">
    <xsd:element name="type2" type="foo:type2"/>
    <xsd:complexType name="type2">
        <xsd:attribute name="value2" type="xsd:int" use="required"/>
    </xsd:complexType>
</xsd:schema>

test3.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:foo="http://www.codesynthesis.com/foo"
            xmlns:bar="http://www.codesynthesis.com/bar"
            targetNamespace="http://www.codesynthesis.com/bar">
    <xsd:import namespace="http://www.codesynthesis.com/foo" 
schemaLocation="test1.xsd"/>
    <xsd:import namespace="http://www.codesynthesis.com/foo" 
schemaLocation="test2.xsd"/>
    <xsd:element name="type3" type="bar:type3"/>
    <xsd:complexType name="type3">
        <xsd:all>
            <xsd:element name="type1" type="foo:type1"/>
            <xsd:element name="type2" type="foo:type2"/>
        </xsd:all>
    </xsd:complexType>
</xsd:schema>

Thanks,
Matt

Boris Kolpackov wrote:
> Hi Matt,
>
>   
> If the two schemas have the same XML Schema namespace (no namespace
> in your case) and one includes the other then you will have to use
> the same C++ namespace for both.
>
> The only way to achieve what you want would be to put the two schemas
> into different XML Schema namespaces and use import instead of include.
>
> Boris




More information about the xsd-users mailing list