ZVON > Tutorials > XML Schema and Relax NG Tutorial
Index | >> Example 5 / 10 << | Prev | Next |
Contents > Wildcard patterns > Attributes must not be from some particular namespaces

Attributes must not be from some particular namespaces

  1. XML Schema
  2. Relax NG
Relax NG keys: anyName, except, nsName

1. XML Schema

The root element named "root" can have an arbitrary number of attributes from any namespace, except let's say "http://bar" and "http://baz". I do not know, how to do this with XML Schema.

2. Relax NG

We will exclude all attributes from namespaces "http://bar" and "http://baz" using the "except" and "nsName" elements.

Invalid document
Attribute is from namespace "http://bar" (that's not allowed).


<root bar:a="1" xmlns="http://foo" xmlns:bar="http://bar" />

Invalid document
Attribute is from namespace "http://baz" (that's not allowed).


<root baz:a="1" xmlns="http://foo" xmlns:baz="http://baz" />

Valid document


<root a="1" xmlns="http://foo" />

Valid document


<foo:root bzz:a="1" xmlns:foo="http://foo" xmlns:bzz="http://bzz" />

Correct Relax NG schema (correctRelax_0.rng)


<grammar ns="http://foo" xmlns="http://relaxng.org/ns/structure/1.0" >

  <start>
    <element>
      <name>root</name>
      <zeroOrMore>
        <attribute>
          <anyName>
            <except>
              <nsName ns="http://bar"/>
              <nsName ns="http://baz"/>
            </except>
          </anyName>
          <text/>
        </attribute>
      </zeroOrMore>
      <text/>
    </element>
  </start>
</grammar>