ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 2 / 3 << | Prev | Next | |
If we use the attribute "schemaLocation", we say that the schema is for element from some particular namespace. In schema, you need to use the "targetNamespace" attribute, which defines the namespace, from which the element must be.
Valid document <f:root xsi:schemaLocation="http://foo correct_0.xsd" xmlns:f="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > test </f:root> |
Correct XML Schema (correct_0.xsd) <xsd:schema targetNamespace="http://foo" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <xsd:element name="root" type="xsd:string"/> </xsd:schema> |
See, how easily this can be accomplished using Relax NG. The pattern <name ns="http://foo">root</name> says, that the root element must be named "root" and that it must be from the namespace "http://foo".
Valid document <root xmlns="http://foo" > test </root> |
Correct Relax NG schema (correctRelax_0.rng) <grammar xmlns="http://relaxng.org/ns/structure/1.0" > <start> <element> <name ns="http://foo">root</name> <text/> </element> </start> </grammar> Correct Relax NG schema (correctRelax_1.rng) |