ZVON > Tutorials > XML Schema and Relax NG Tutorial |
Intro / Search / ZVON |
Index | >> Example 1 / 3 << | Prev | Next | |
Please, send all comments, bug-reports, and contributions to Jiri.Jirat@systinet.com. Thank you very much.
XML Schema keys: attributeFormDefault, attributeThe target namespace is not null here. If the attribute "attributeFormDefault" is set to "qualified", the attribute "xx" must be from the target namespace.
Valid document <f:root xsi:schemaLocation="http://foo correct_0.xsd" f:xx="1" xmlns:f="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> Invalid document <f:root xsi:schemaLocation="http://foo correct_0.xsd" xx="1" xmlns:f="http://foo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> |
Correct XML Schema (correct_0.xsd) <xsd:schema targetNamespace="http://foo" attributeFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:foo="http://foo" > <xsd:element name="root"> <xsd:complexType> <xsd:attribute name="xx" type="xsd:string" use="required"/> </xsd:complexType> </xsd:element> </xsd:schema> |
If we want the attribute to be from some particular non-null namespace, we must specify this explicitly, using the "name" element with "ns" attribute, or element "attribute" with both "name" and "ns" attributes.
Valid document <f:root f:xx="1" xmlns:f="http://foo" /> Invalid document <f:root xx="1" xmlns:f="http://foo" /> |
Correct Relax NG schema (correctRelax_0.rng) <grammar ns="http://foo" xmlns="http://relaxng.org/ns/structure/1.0" > <start> <element name="root"> <attribute> <name ns="http://foo">xx</name> <text/> </attribute> <empty/> </element> </start> </grammar> Correct Relax NG schema (correctRelax_1.rng) |