Including element from one schema namespace in another schema namespace

Discussion in 'XML' started by mflll@wiu.edu, Jul 19, 2006.

  1. Guest

    How does one say in one schema that one wants an element defined in
    another schema. For example, I want to include in the Employee
    definition, an Address element defined in the schema
    http://test.org.Address

    Here is the schema defining the Employee:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema targetNamespace="http://test.org/emp"
    xmlns="http://test.org/emp"
    xmlns:addr="http://test.org/Address"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" version="2.0">
    <xsd:import namespace="http://test.org/Address"
    schemaLocation="Address.xsd"/>


    <xsd:complexType name = "EmployeeType">
    <xsd:sequence>
    <xsd:element ref="Name" minOccurs="1" maxOccurs="1"/>
    <xsd:element ref="JobInfo" minOccurs="0" maxOccurs="unbounded"/>
    <xsd:element ref="Salary" minOccurs="0" maxOccurs="1" />
    <addr:Address minOccurs="1" maxOccurs="1"/>
    </xsd:sequence>
    </xsd:complexType>
    ....
    </xsd:schema>

    Here is the definition of the Address:

    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema targetNamespace="http://test.org/Address"
    xmlns="http://test.org/address"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified" version="2.0">

    <xsd:complexType name="addressType">
    <xsd:sequence>
    <xsd:element minOccurs="1" maxOccurs="unbounded"
    name="Line"><xsd:simpleType><xsd:restriction
    base="xsd:string"/></xsd:simpleType></xsd:element>
    <xsd:element minOccurs="1" maxOccurs="1"
    name="City"><xsd:simpleType><xsd:restriction
    base="xsd:string"/></xsd:simpleType></xsd:element>
    <xsd:element minOccurs="1" maxOccurs="1"
    name="State"><xsd:simpleType><xsd:restriction
    base="xsd:string"/></xsd:simpleType></xsd:element>
    <xsd:element minOccurs="1" maxOccurs="1"
    name="zip"><xsd:simpleType><xsd:restriction
    base="xsd:string"/></xsd:simpleType></xsd:element>
    </xsd:sequence>
    </xsd:complexType >
    <xsd:element name="address" type="addressType"/>
    </xsd:schema>

    This gives me an error message.

    Note, I have no problems bringing in a type from one schema into
    another. That is, I created an addressType in the
    http://test.org/Address
    name space. I used that just fine to define an element in the
    http://test.org/emp Schema. I am wondering if there is a way to bring
    in an element itself from one schema into another.

    (I also tried writing using the ref attribute, but ref requires a
    QName, not
    a NCName. So I got a syntax error message if I was to write
    <xsd:element ref="emp:Address")

    Dr. Laurence L. Leff, Ph.D. Associate Professor of Computer Science
    Western Illinois University 1 University Circle Macomb IL 61455 309 367
    0787
    , Jul 19, 2006
    #1
    1. Advertising

  2. George Bina Guest

    Hi,

    First note that XML Schema component names are case sensitive and
    address and Address are different components.
    If you want to specify that the content of EmployeeType should contain
    an element from the http://test.org/Address namespace named address
    then use

    <xs:element ref="addr:address"/>

    Best Regards,
    George
    ---------------------------------------------------------------------
    George Cristian Bina
    <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
    http://www.oxygenxml.com

    wrote:
    > How does one say in one schema that one wants an element defined in
    > another schema. For example, I want to include in the Employee
    > definition, an Address element defined in the schema
    > http://test.org.Address
    >
    > Here is the schema defining the Employee:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsd:schema targetNamespace="http://test.org/emp"
    > xmlns="http://test.org/emp"
    > xmlns:addr="http://test.org/Address"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > elementFormDefault="qualified" version="2.0">
    > <xsd:import namespace="http://test.org/Address"
    > schemaLocation="Address.xsd"/>
    >
    >
    > <xsd:complexType name = "EmployeeType">
    > <xsd:sequence>
    > <xsd:element ref="Name" minOccurs="1" maxOccurs="1"/>
    > <xsd:element ref="JobInfo" minOccurs="0" maxOccurs="unbounded"/>
    > <xsd:element ref="Salary" minOccurs="0" maxOccurs="1" />
    > <addr:Address minOccurs="1" maxOccurs="1"/>
    > </xsd:sequence>
    > </xsd:complexType>
    > ....
    > </xsd:schema>
    >
    > Here is the definition of the Address:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsd:schema targetNamespace="http://test.org/Address"
    > xmlns="http://test.org/address"
    > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    > xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    > elementFormDefault="qualified" version="2.0">
    >
    > <xsd:complexType name="addressType">
    > <xsd:sequence>
    > <xsd:element minOccurs="1" maxOccurs="unbounded"
    > name="Line"><xsd:simpleType><xsd:restriction
    > base="xsd:string"/></xsd:simpleType></xsd:element>
    > <xsd:element minOccurs="1" maxOccurs="1"
    > name="City"><xsd:simpleType><xsd:restriction
    > base="xsd:string"/></xsd:simpleType></xsd:element>
    > <xsd:element minOccurs="1" maxOccurs="1"
    > name="State"><xsd:simpleType><xsd:restriction
    > base="xsd:string"/></xsd:simpleType></xsd:element>
    > <xsd:element minOccurs="1" maxOccurs="1"
    > name="zip"><xsd:simpleType><xsd:restriction
    > base="xsd:string"/></xsd:simpleType></xsd:element>
    > </xsd:sequence>
    > </xsd:complexType >
    > <xsd:element name="address" type="addressType"/>
    > </xsd:schema>
    >
    > This gives me an error message.
    >
    > Note, I have no problems bringing in a type from one schema into
    > another. That is, I created an addressType in the
    > http://test.org/Address
    > name space. I used that just fine to define an element in the
    > http://test.org/emp Schema. I am wondering if there is a way to bring
    > in an element itself from one schema into another.
    >
    > (I also tried writing using the ref attribute, but ref requires a
    > QName, not
    > a NCName. So I got a syntax error message if I was to write
    > <xsd:element ref="emp:Address")
    >
    > Dr. Laurence L. Leff, Ph.D. Associate Professor of Computer Science
    > Western Illinois University 1 University Circle Macomb IL 61455 309 367
    > 0787
    >
    George Bina, Jul 20, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vish
    Replies:
    2
    Views:
    1,724
    Steve C. Orr, MCSD
    Jul 16, 2003
  2. Y.S.
    Replies:
    3
    Views:
    1,004
    strajan
    Sep 17, 2003
  3. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,244
    Stanimir Stamenkov
    Apr 25, 2005
  4. S. Robert James

    including a namespace for just one class

    S. Robert James, Dec 25, 2006, in forum: Ruby
    Replies:
    5
    Views:
    148
    Logan Capaldo
    Dec 28, 2006
  5. OccasionalFlyer
    Replies:
    6
    Views:
    245
    Garrett Smith
    Jul 29, 2009
Loading...

Share This Page