- From: Jeni Tennison <jeni@jenitennison.com>
- Date: Mon, 24 Jun 2002 17:41:01 +0100
- To: Nicolas SABOURET <Nicolas.Sabouret@limsi.fr>
- CC: xmlschema-dev@w3.org
Hi Nicolas, > I'd like to write a schema in which one element (say foo) should > have a content of type xpath. I'd like not to write : > <xsd:element name="foo" type="xsd:string"/> > But rather something like : > <xsd:element name="foo" type="xpath"/> > thus specifying that I want to respect the xpath syntax within this > element's content. Is this possible ? Well, you can define your own simple type called 'xpath', and refer to that: <xs:element name="foo" type="xpath" /> <xs:simpleType name="xpath"> ... </xs:simpleType> The problem is then how to define the simple type; it's not one of the built-in XML Schema data types, so you have to define it yourself, and the closest thing would be a xs:token (so that whitespace is collapsed) with a regular expression (pattern facet) to do the validation. That's where things get difficult because (as I understand it), full XPath isn't a regular language so it's impossible to write a regular expression to test it. There are subsets of XPath that can be expressed as a regular expression. For example, you could write a regular expression for location paths that only used the child and attribute axes, like: <xs:simpleType name="xpath"> <xs:restriction base="xs:token"> <xs:pattern value="/?(((\i\c*:)?\i\c*)|\*)(/@?(((\i\c*:)?\i\c*)|\*))+" /> </xs:restriction> </xs:simpleType> ( \i\c* is an XML name; (\i\c*:)?\i\c* is a QName; ((\i\c*:)?\i\c*)|\* is an XPath name test ) But you might find that simply having a type named 'xpath' is enough to tell people using the language that the value of the element should be an XPath. Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/
Received on Monday, 24 June 2002 12:41:03 UTC