ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 9 / 10 << | Prev | Next | |
The root element named "root" can have an arbitrary number of any elements 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 elements which are from namespace other than targetNamespace.
Valid document <root xsi:schemaLocation="http://foo correct_0.xsd" xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <a:a xmlns:a="http://bar" /> </root> Valid document <root xsi:schemaLocation="http://foo correct_0.xsd" xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <a xmlns=""/> </root> Invalid document <foo:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <foo:a/> </foo:root> |
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:sequence minOccurs="1" maxOccurs="1"> <xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="skip"/> </xsd:sequence> </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 the "target namespace" using the "except" and "nsName" elements.
Valid document <root xmlns="http://foo" > <a:a xmlns:a="http://bar" /> </root> Valid document <root xmlns="http://foo" > <a xmlns=""/> </root> Invalid document <foo:root xmlns:foo="http://foo" > <foo:a/> </foo:root> |
Correct Relax NG schema (correctRelax_0.rng) |