ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 4 / 4 << | Prev | Next | |
Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.
XML Schema keys: elementFormDefaultBecause the attribute "elementFormDefault" is set to "qualified", the child must be from the namespace "http://foo" (from the "targetNamespace").
Valid document <root xsi:schemaLocation="http://foo correct_0.xsd" xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <e1>Element 1</e1> </root> Invalid document <root xsi:schemaLocation="http://foo correct_0.xsd" xmlns="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <e1 xmlns="">Element 1</e1> </root> |
Correct XML Schema (correct_0.xsd) <xsd:schema targetNamespace="http://foo" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:foo="http://foo" > <xsd:element name="root"> <xsd:complexType> <xsd:sequence> <xsd:element name="e1" type="xsd:string"/> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> |
We can set the namespace for all elements using the "ns" attribute. The value is inherited and now all elements must be from the "http://foo" namespace.
Valid document <root xmlns="http://foo" > <e1>Element 1</e1> </root> |
Correct Relax NG schema (correctRelax_0.rng) |