[ACCEPTED]-XSD with elements from other namespace-xml-namespaces

Accepted answer
Score: 37

There are actually two different ways to 17 compose XML Schema documents: <xs:import> and <xs:include>. xs:include 16 is intended to be used when the namespace 15 of the containing document is the same as 14 the one being referenced, so it's not quite 13 what you're looking for. xs:import is better 12 for your situation when you need to reference 11 all (or a subset) of elements in the referenced 10 schema and they're in a different target 9 namespace. There's a question here on the 8 differences: What&#39;s the difference between xsd:include and xsd:import?.

Anyway, back to this specific 7 question. What you probably want is something 6 like this:

<?xml version="1.0" encoding="utf-8"?>
 <xs:import namespace="http://example.com/namespace/for/ElementA" schemaLocation="A.xsd" /> 
 <xs:element name="ElementB">
    <xs:element name="foo" type="xs:string" />
    <xs:element name="bar" type="xs:string" />
    <!-- This introduces a element named ElementA that uses the ComplexType ea:ElementA defined in A.xsd -->
    <xs:element name="ElementA" type="ea:ElementA" />

Though you'll need A.xsd to create 5 a complex type for ElementA that you can 4 use in B.xsd as shown.

This arcticle has 3 some good information/examples and includes 2 a discussion of some of the different composability 1 strategies: http://www.xfront.com/ZeroOneOrManyNamespaces.html

Score: 0

You could use <xsd:import> tag to import a schema with 1 another namespace.

More Related questions