W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2008

RE: Schema that mandates elements and attributes from disparate namespaces?

From: Gavin Kistner <phrogz@mac.com>
Date: Fri, 14 Mar 2008 11:45:51 -0700
To: Michael Kay <mike@saxonica.com>
Cc: xmlschema-dev@w3.org
Message-ID: <20DF0D9F-0118-1000-DE8E-B00BF644BE33-Webmail-10021@mac.com>

On Friday, March 14, 2008, at 01:15AM, "Michael Kay" <mike@saxonica.com> wrote:
>Yes, you can do this. You just use
><xs:attribute ref="foo:msg"/>
><xs:element ref="bar:charlie"/>
>In this schema document you need to declare the namespace prefix and do an
>xs:import for the schema document where the other attribute/element is
>declared; then you put the declaration itself in a separate module with a
>different targetNamespace.

Thank you for your help; I had actually tried this, but had made typos in my namespaces and thought I was on the wrong track. Trying it again proved successful.

For the archives, here's a triplet of sample files showing the success:

<!-- foo.xsd -->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:bar="http://www.bar.com" xmlns="http://www.foo.com/">
  <xs:import namespace="http://www.bar.com" schemaLocation="bar.xsd"/>
  <xs:element name="root">
        <xs:element name="native">
            <xs:attribute ref="bar:foreign" use="required"/>
        <xs:element ref="bar:jim"/>

<!-- bar.xsd -->
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.bar.com">
  <xs:element name="jim">
      <xs:attribute name="whee" type="xs:string" use="required"/>
  <xs:attribute name="foreign" type="xs:string" fixed="YAY" />  

<!-- foo_test.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:bar="http://www.bar.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
  <native bar:foreign="YAY"/>
  <bar:jim whee="all good"/>
Received on Friday, 14 March 2008 18:46:31 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:14 UTC