Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: Gavin Kistner <phrogz@---.--->
To: Michael Kay <mike@--------.--->
Date: 3/14/2008 4:46:00 AM
On Friday, March 14, 2008, at 01:15AM, "Michael Kay" <mike@s...> wrote:
>Yes, you can do this. You just use
><xs:attribute ref="foo:msg"/>
>or
><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:complexType>
      <xs:sequence>
        <xs:element name="native">
          <xs:complexType>
            <xs:attribute ref="bar:foreign" use="required"/>
          </xs:complexType>
        </xs:element>
        <xs:element ref="bar:jim"/>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

<!-- 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:complexType>
      <xs:attribute name="whee" type="xs:string" use="required"/>
    </xs:complexType>
  </xs:element>
  <xs:attribute name="foreign" type="xs:string" fixed="YAY" />  
</xs:schema>

<!-- 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"/>
</root>



From phrogz@m... Fri Mar 14 19:02:58 2008
Received: from lisa.w3.org ([128.30.52.41])


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent