|
The weakly typed credit transations example in this article can be validated using the following RELAX NG schema (without XPath or XSLT). For the sake of brevity, the RELAX NG is specified using RELAX NG's non-XML syntax. To obtain an equivalent schema in RELAX NG's "official" XML syntax, use James Clark's non-XML syntax translator (http://www.thaiopensource.com/relaxng/nonxml/). Use Jing (http://thaiopensource.com/relaxng/jing.html) or some other RELAX NG validation tool to validate the XML "Sales" data against the output from the non-XML syntax translator.
# RELAX NG schema for XML.com credit transactions # example
# The content model for element Sale varies
# depending on the value of attribute Means.
datatypes xsd =
"http://www.w3.org/2001/XMLSchema-datatypes"
namespace xsi =
"http://www.w3.org/2001/XMLSchema-instance"
start = Sales
Sales = element Sales {
(attribute xsi:noNamespaceSchemaLocation { xsd:anyURI })?,
Sale+
}
Sale = InPersonSale | InternetSale | MailSale | OtherSale
InPersonSale = element Sale {
(attribute Means { "In person" }),
(element SignatureVerifiedBy { xsd:string }),
(element VisuallyIdentifiedBy { xsd:string }),
ItemAndPrice
}
InternetSale = element Sale {
(attribute Means { "Internet" }),
(element DigitalSignature { xsd:string }),
ItemAndPrice
}
MailSale = element Sale {
(attribute Means { "Mail" }),
(element SignatureVerifiedBy { xsd:string }),
ItemAndPrice
}
OtherSale = element Sale {
(attribute Means { "Phone" | "Fax" }),
ItemAndPrice
}
ItemAndPrice =
(element Item { xsd:string }),
(element Price {xsd:decimal })
|