-1

I have 2 separate XSDs with some common attributes. I want to create another XSD and put all my common attributes in the separate XSD and import them in the 2 XSDs i have already rather than repeating them or duplicating them in both the XSDs.

Is there any reference for such implementation?

nisha
  • 703
  • 2
  • 14
  • 28
  • What do you mean by "reference for such implementation"? This can be done using xsd:import and xsd:include. Here a question asked previously that maybe can help. http://stackoverflow.com/questions/2357943/whats-the-difference-between-xsdinclude-and-xsdimport – user1187008 Jul 30 '12 at 13:31
  • http://www.liquid-technologies.com/Tutorials/XmlSchemas/XsdTutorial_04.aspx helped.. Thanks .. – nisha Jul 30 '12 at 13:35
  • possible duplicate of [importing common attributes in XSD](http://stackoverflow.com/questions/11716829/importing-common-attributes-in-xsd) – tom redfern Jul 30 '12 at 14:27

1 Answers1

0

We do it like this:

Shared "library" xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.common.namespace/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.common.namespace/">
    <xs:attribute name="ACommonAttribute" type="xs:float" default="1.7"/>
</xs:schema>

Left xsd with same target namespace:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://www.common.namespace/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.common.namespace/">
    <xs:include schemaLocation="Common.xsd"/>
    <xs:element name="MyLeftElement">
        <xs:annotation>
            <xs:documentation>Comment describing your root element</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:attribute ref="ACommonAttribute"/>
        </xs:complexType>
    </xs:element>
</xs:schema>

Right xsd with different target namespace (needs an Import instead if an Include statement)

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns="http://another.namespace/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:libs="http://www.common.namespace/" targetNamespace="http://another.namespace/">
    <xs:import namespace="http://www.common.namespace/" schemaLocation="Common.xsd"/>
    <xs:complexType name="RightComplexType">
        <xs:sequence>
            <xs:element name="Bit">
                <xs:complexType>
                    <xs:attribute ref="libs:ACommonAttribute"/>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:schema>
RoboJ1M
  • 1,590
  • 2
  • 27
  • 34