ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 3 / 10 << | Prev | Next | |
The root element named "root" can have arbitrary number of any attributes from namespace other than the target namespace. The target namespace is not null here. The "namespace" attribute will be set to value "##other". It will allow all attributes which are from namespace other than targetNamespace or null.
Valid document <root xsi:schemaLocation="http://foo correct_0.xsd" a:a="1" xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:a="http://bar" /> Invalid document <root xsi:schemaLocation="http://foo correct_0.xsd" a="1" xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> Invalid document <foo:root xsi:schemaLocation="http://foo correct_0.xsd" foo:a="1" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> |
Correct XML Schema (correct_0.xsd) <xsd:schema targetNamespace="http://foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root"> <xsd:complexType> <xsd:anyAttribute namespace="##other" processContents="skip"/> </xsd:complexType> </xsd:element> </xsd:schema> |
The element "anyName" says that the attribute can have any name from any namespace. We will exclude all attributes from empty namespace and the "target namespace" using the "except" and "nsName" elements.
Valid document <root xmlns="http://foo" /> Valid document <root bar:a="1" xmlns="http://foo" xmlns:bar="http://bar" /> Invalid document <root a="1" xmlns="http://foo" /> Invalid document <foo:root foo:a="1" xmlns:foo="http://foo" /> |
Correct Relax NG schema (correctRelax_0.rng) |