XML.com: XML From the Inside Out

XML.comWebServices.XML.comO'Reilly Networkoreilly.com
  Articles | Weblogs | Newsletter | Safari Bookshelf
advertisement

Article:
 Beyond W3C XML Schema
Subject: weak typing with RELAX NG
Date: 2002-04-12 11:27:34
From: Joshua Lubell

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 })


No Previous Message Previous Message   Next Message Next Message

Sponsored By:


Contact Us | Our Mission | Privacy Policy | Advertise With Us | | Submissions Guidelines
Copyright © 2008 O'Reilly Media, Inc. | (707) 827-7000 / (800) 998-9938