| 1. | How are datatypes specified? | ||||
The type attribute of the data element is used to specify one of the built-in datatypes, e.g. for a 16 bit integer,
<define name="SmallInt">
<element name="smallInt">
<data type="short"/>
</element>
</define>
provides the schema for an instance of
<smallInt>32767</smallInt>
Which allows for a signed 16 bit integer. Eric van der Vlist provides a more complete list of the datatypes. | |||||
| 2. | Facet, param ? | ||||
| |||||
| 3. | Conformance and data type libraries | ||||
The last para of 4.16 is very clear. A data or value element must be correct in its use of datatypes. Specifically, the type attribute must identify a datatype within the datatype library identified by the value of the datatypeLibrary attribute. For a data element, the parameter list must be one that is allowed by the datatype (see Section 6.2.8). | |||||
| 4. | Exclusive attribute values. | ||||
I'm trying to define an attribute that can have a list of one or more (up to three) mutually exclusive values. For example, all the following are valid: <test state="hide"/> <test state="hide enable"/> <test state="hide enable lower"/> <test state="show raise"/> <test state="raise show"/> I tried to specify the element and attribute as follows:
<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">
<start>
<ref name="test"/>
</start>
<define name="test">
<element name="TEST">
<attribute name="state">
<interleave>
<choice>
<value>hide</value>
<value>show</value>
</choice>
<choice>
<value>enable</value>
<value>disable</value>
</choice>
<choice>
<value>raise</value>
<value>lower</value>
</choice>
</interleave>
</attribute>
</element>
</define>
</grammar>
However, when I run jing on this to verify it, I get the following message: test.rng:8:31: error: interleave of "string" or "data" element David Tolpin replies The specification explains this in 7.2 String sequences. One cannot have strings interleaved or grouped. Thus you are probably out of luck unless you list all combinations of attribute constituents. John Cowan adds You have stepped on one of the very few arbitrary restrictions of RNG: you can't interleave typed data, only elements and text. You could write a bit of XSLT to generate all the cases. There are 27 logical cases.
Total physical cases: 79. David comes back One should not go so far. Relax NG is not that bad. hl=("hide"|"show")?
ed=("enable"|"disable")?
lr=("raise"|"lower")?
state=attribute state {list {
(hl,((ed,lr)|(lr,ed)))
| (lr,((hl,ed)|(ed,hl)))
| (ed,((hl,lr)|(lr,hl)))}}
start = element test { state }
Choice is allowed. But in general, regular expressions with interleave would help. rng form is:
<define name="Options">
<element name="options">
<ref name="OptAtts"/>
</element>
</define>
<define name="OptAtts">
<attribute name="state">
<list>
<choice>
<group>
<ref name="hl"/>
<choice>
<group>
<ref name="ed"/>
<ref name="lr"/>
</group>
<group>
<ref name="lr"/>
<ref name="ed"/>
</group>
</choice>
</group>
<group>
<ref name="lr"/>
<choice>
<group>
<ref name="hl"/>
<ref name="ed"/>
</group>
<group>
<ref name="ed"/>
<ref name="hl"/>
</group>
</choice>
</group>
<group>
<ref name="ed"/>
<choice>
<group>
<ref name="hl"/>
<ref name="lr"/>
</group>
<group>
<ref name="lr"/>
<ref name="hl"/>
</group>
</choice>
</group>
</choice>
</list>
</attribute>
</define>
<define name="hl">
<optional>
<choice>
<value>hide</value>
<value>show</value>
</choice>
</optional>
</define>
<define name="ed">
<optional>
<choice>
<value>enable</value>
<value>disable</value>
</choice>
</optional>
</define>
<define name="lr">
<optional>
<choice>
<value>raise</value>
<value>lower</value>
</choice>
</optional>
</define>
<options state="show enable"/>
<options state="disable hide lower "/>
<options state="lower "/>
now shows as valid.
| |||||
| 5. | Regex for email addresses, rfc 2822 | ||||
I've looked into the spec once again and found that comments and spaces are not allowed inside the address parts (local @ domain), only between them, additionally, it is said that comments and white space should not be used around @. (Comments are in parentheses before or after the address, with parentheses inside quoted -- this is not reqular expression, because it requires matching of nested parentheses). If you want with just addresses, without comments, then the expression is start=element addr-spec {
xsd:token {
pattern="""([a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+(\.[a-zA-Z0-9!#$%&'*+\-/=
?\^_`{|}~]+)*|"[^"\\]*")@([a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+(\.[a-zA-Z0-9!#$%&'
*+\-/=?\^_`{|}~]+)*|\[[^\[\]\\]*\])"""
}
}
Ednote: Please rejoin the above lines.
Works for both normal addresses and forms like "David Tolpin"@[Obscure Place] The expression above is slightly more allowing than required, but should be appropriate for the majority of cases. If you want comments too:
then the regular expression must be prepended and appended with regexps for the comments, and becomes
start=element addr-spec {
xsd:token {
pattern=
"(\(([^\(\)\\]|\\.)*\) )?"
~
"""([a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+(\.[a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+)*|
"([^"\\]|\\.)*")"""
~ "@"
~
"([a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+(\.[a-zA-Z0-9!#$%&'*+\-/=?\^_`{|}~]+)*|\[
([^\[\]\\]|\\.)*\])"
~ "( \(([^\(\)\\]|\\.)*\))?"
}
}
I.e., things in parentheses are possible in the beginning and end of the address. I have split it this time into parts
|