ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 1 / 8 << | Prev | Next | |
Both target namespaces are the same, so inclusion won't have any further effects on the namespace settings in the included schema, although the form of the element "x" in the included schema is "qualified". Schema Representation Constraint: Inclusion Constraints and Semantics .
Valid document <foo:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <foo:x>dhhglh</foo:x> </foo: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" > <x xmlns="">dhhglh</x> </foo:root> |
Correct XML Schema (correct_0.xsd) <xsd:schema targetNamespace="http://foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:foo="http://foo" > <xsd:include schemaLocation="correct_1.xsd"/> <xsd:element name="root" type="foo:myType"/> </xsd:schema> Correct XML Schema (correct_1.xsd) <xsd:schema targetNamespace="http://foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:complexType name="myType"> <xsd:sequence> <xsd:element name="x" minOccurs="1" maxOccurs="1" type="xsd:string" form="qualified"/> </xsd:sequence> </xsd:complexType> </xsd:schema> |
Both target namespaces are the same, so inclusion won't have any further effects on the namespace settings in the included schema, although the form of the element "x" in the included schema is "unqualified".
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:x>dhhglh</foo:x> </foo:root> Valid document <foo:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:foo="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > <x xmlns="">dhhglh</x> </foo:root> |
Correct XML Schema (correct_0.xsd) <xsd:schema targetNamespace="http://foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:foo="http://foo" > <xsd:include schemaLocation="correct_1.xsd"/> <xsd:element name="root" type="foo:myType"/> </xsd:schema> Correct XML Schema (correct_1.xsd) <xsd:schema targetNamespace="http://foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:complexType name="myType"> <xsd:sequence> <xsd:element name="x" minOccurs="1" maxOccurs="1" type="xsd:string" form="unqualified"/> </xsd:sequence> </xsd:complexType> </xsd:schema> |
In this example there is no "ns" attribute in the included document. During the schema processing, the document is included before the "ns" attribute is propagated, so the value of "ns" attribute will propagate to the included document. We validate the XML files against the first Relax NG schema (which includes the second one).
Valid document <foo:root xmlns:foo="http://foo" > <foo:x>dhhglh</foo:x> </foo:root> Invalid document <foo:root xmlns:foo="http://foo" > <x xmlns="">dhhglh</x> </foo:root> |
Correct Relax NG schema (correctRelax_0.rng) <grammar ns="http://foo" xmlns="http://relaxng.org/ns/structure/1.0" > <start> <element name="root"> <ref name="myType"/> </element> </start> <include href="correctRelax_1.rng"/> </grammar> Correct Relax NG schema (correctRelax_1.rng) |