Hi Dave,
The script below should do that:
<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
startMode="start">
<mode name="start">
<namespace ns="http://a">
<validate schema="a.xsd" useMode="B"/>
</namespace>
</mode>
<mode name="B">
<namespace ns="http://b">
<validate schema="b.xsd"/>
</namespace>
</mode>
</rules>
This will basically allow a document to start with the first namespace
to contain content in the second namespace.
If you want to have content from the second namespace and inside that
again content from the first namespace and you want to validate the a
namespace as if b does not appear in the document then a script like
below will do it. Note that the script below will allow content in a
namespace different than the first if that is in side inside the content
in the second namespace or below. See also the comments in the script below:
<?xml version="1.0" encoding="UTF-8"?>
<rules xmlns="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"
xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
startMode="start">
<!--
The inital mode. It allows the document to start only with the
first namespace
because the default reject action on any namespace will reject
any other content.
-->
<mode name="start">
<namespace ns="http://a">
<!-- Validate with the schema for the first namespace and
the child sections
(those will be in other namespaces) will be processed with
mode B rules -->
<validate schema="a.xsd" useMode="B"/>
</namespace>
</mode>
<!-- The B mode is used on sections inside the initial section,
It allows only the second namespace, other namespaces are
rejected by the
default <anyNamepsace><reject/></anyNamepsace> rule.
-->
<mode name="B">
<namespace ns="http://b">
<!-- Validates the section in the second namespace against
the second schema.
Further content in other namespaces is processed with
the allow mode that
just allows anything so the validation is striclty
applied to the current section.
-->
<validate schema="b.xsd" useMode="allow"/>
<!-- The second action contributes to the validation
candidate of the parent
validate action, the one started in the initial mode,
the validate against the
first schema. This says ignore this section in the b
namespace and process
further sections using the mode attachA.
-->
<unwrap useMode="attachA"/>
</namespace>
</mode>
<!-- This allows any content from any namespace.
Used to process descendant sections of a section in the second
namespace
from the B mode above, to allow any content inside those sections -->
<mode name="allow">
<anyNamespace>
<allow/>
</anyNamespace>
</mode>
<!-- This attaches content from the first namespace to the parent
validate action,
that in our case is the validate action from the initial mode and
ignores the sections
in other namespaces. Implicitely the same mode is used for the
attach and unwrap
actions so all the eventual descendant sections are processed by
attaching all the
content in the first namespace no matter how deep that appears in
the document-->
<mode name="attachA">
<namespace ns="http://a">
<attach/>
</namespace>
<anyNamespace>
<unwrap/>
</anyNamespace>
</mode>
</rules>
Best Regards,
George
-- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com Dave Pawson wrote: > Sigh. I do feel silly. > I clearly do not understand the basic processing model. > > 2008/5/22 George Cristian Bina <george@oxygenxml.com>: >> In your initial example you had >> <attach/> >> which is equivalent with >> <attach useMode="activity"/> >> because if there is no useMode specified the current mode will be used. >> That means the interpretations will be: >> >> (R, validateR) (W, validateW) (D, validateD) >> (R, validateR) (W, attach) (D, reject) >> >> and what happens is >> >> ValidateR will be applied on a fragment containing R and W >> ValidateW will be applied on a fragment containing W >> ValidateD will be applied on a fragment containing D >> reject will be applied on a fragment contaning D >> >> So, the error message was not from the ValidateW action but from the reject >> action. >> >> If a mode does not have a rule on anyNamespace then the default action will >> be reject and when the D section is processed in the second interpretation >> against the activity mode, none of the activity mode rules matches so the >> reject action will be taken, resulting the (D, reject) pair from the second >> interpretation. > > Taking a more general approach then: > > If I have > > <a xmlns='a'> > <b xmlns='b'/> > </a> > > Is it possible to define a schema that only has element a, > another schema that has element b > > and have a mode in my nvdl script which validates 'a' against schema 'a', > *but does not allow element b* (i.e. takes the default reject action). > I'd like to then change modes such that I can validate b against schema b. > > I.e. I'm trying to avoid the "process the rest of the child elements > of 'a' against the anything content model" > approach, by changing modes as soon as an element not in the 'a' namespace is > met. > > I want to write a schema for 'a' which has no knowledge of 'b' > namespaced elements. > Then to write a schema for 'b' which is complete. > > ((I know I am ignoring the problem of *where* in the 'a' schema the 'b' model > can occur, but I am trying to understand more of the processing model, and I > keep forgetting the defaults!)) > > TIA > > > > > -- DSDL comments To unsubscribe, please send a message with the command "unsubscribe" to dsdl-comment-request@dsdl.org (mailto:dsdl-comment-request@dsdl.org?Subject=unsubscribe)Received on Fri May 23 08:09:13 2008
This archive was generated by hypermail 2.1.8 : Sat May 24 2008 - 15:33:04 UTC