|
||||||||||||||||||||||||||||||||||
IntroductionDPML is a declarative XML processing language that is itself XML. It is more than a simple transform pipelining language as it allows conditional processing, loops, sub-routines, and exception handling. It considers XML documents as the basic data quantum and URIs as the method of addressing them. The XML processing instructions and resolution of URI schemes are abstracted from the language so as to be fully extensible. In this document we refer to a document containing DPML as an Instruction Document or idoc. The RelaxNG schema for a DPML idoc can be found here. High Level StructureThe root element of a DPML idoc must be <idoc>
<seq> <seq> <instr /> <instr /> </seq> <instr /> </seq> </idoc> Optional Namespace
An optional namespace <dpm:idoc xmlns:dpm="http://1060.org/dpm">
<dpm:seq> <dpm:seq> <dpm:instr /> <dpm:instr /> </dpm:seq> <dpm:instr /> </dpm:seq> </dpm:idoc> InstructionsInstruction Reserved ElementsThe following elements names have special meaning and are used to express the type and target URI's of an instruction.
Standard ElementsThe following element names are adopted as a convention. Their types may be either URIs or inline literal XML documents.
<instr>
<type>copy</type> <operand>file:/myOperand.xml</operand> <target>file:/myTarget.xml</target> </instr> With NetKernel 2.1.0, DPML now supports arbitrarily named arguments on an instruction. Most accessors continue to use the standard element names but now any element name can be used (except the reserved names). As with the standard elements, an element may contain either a URI or literal XML document. The URI or literal will be passed as a named argument to the instruction URA, the name will be the same as the element. Data TypesOperands, operators, parameters and targets all reference documents by URIs. All conventional registered URI schemes (file:, http:. ftp:) are usable within an idoc in addition to some internal schemes that are documented here.
Core InstructionsThese instructions are key to the operation of DPML. copyThe copy instruction is used to copy one document into another. See copy instruction reference. dpmlThe dpml instruction is used to execute a sub-routine in another DPML document. See dpml instruction reference. xpathevalThe xpatheval instruction is used to evaluate an xpath expression on a document that is then cast to a boolean true/false value. Useful as a basis of conditional processing. See xpatheval instruction reference. CommentsTraditional XML comments using <!-- can be used, however we recommend using <comment> elements to wrap comments. These can be placed at most places within an idoc and they will be ignored. The benefit is that comments can be processed like regular xml and unlike XML comments they can be nested. <idoc>
<comment>This idoc demostrates use of comments</comment> <seq> <comment>This is the <b>first</b> sequence </comment> <instr> <comment>This is an <a href="http://www.w3.org/">XSLT</a> instruction </comment> <type>xslt</type> <operand type="uri">file:/myOperand.xml</operand> <operator type="uri">file:/myStylesheet.xsl</operator> <target type="response" /> </instr> </seq> </idoc> <comment> may contain nested XML all of which is ignored by a DPML process; comments can therefore include XHTML which makes DPML idoc's easy to document. Conditional ProcessingDPML contains two conditional statements, a simple if-then-else and a more complex choose statement. The structure of the <if>
The instructions within the <cond> <instr /> </cond> <then> <instr /> </then> <else> <instr /> </else> </if> <cond> block are executed first.
Associated with each <cond> block is a this:cond document.
The instructions within a <cond> block must at some point before the end of the block assign a canonical boolean
document to this:cond. The canonical boolean document held in this:cond is evaluated as the result of the cond
block and the conditional branch performed.
If true the <then> block is executed othewise the <else> block
is executed.
The structure of the <choose> The <cond> <instr /> </cond> <then> <instr /> </then> <cond> <instr /> </cond> <then> <instr /> </then> .... <else> <instr /> </else> </choose> <cond> blocks are executed in document order until one evaluates to
true. When a true condition is found the following <then> block is executed. If no conditions
are true and there is an <else> block this is executed.
Loop ProcessingThe structure of the looping while instruction is: <while>
The <cond> <instr /> </cond> <seq> <instr /> </seq> </while> <cond> block is executed first. This
must contain one instruction that returns a canonical boolean document.
This should be target to a variable.
If true the <seq> block is executed. The condition is the re-evaluated
and when true the <seq> block is executed again ad-infinitum.
Care should be taken to avoid infinite loops!
Exception ProcessingWhen processing instructions things may go wrong. They may fail for one of three categories of problem:
The second and third categories of error are runtime exceptions and an idoc may wish to handle them and act accordingly. Exception handling blocks can be placed into the idoc at any location where an instruction
would be valid. The Unhandled errors cause the termination of an idoc and the invoker will receive back a canonical exception document which details the problem.
Inside an exception handling block the idoc has access to the exception that was thrown by using the
URI of Exceptions can be deliberately thrown or more correctly error conditions can be detected and programmatically converted to exceptions using the throw instruction. The following idoc shows an example of throwing a deliberate exception, catching it, and using the exception: <idoc>
<seq> <instr> <type>throw</type> <operand> <ex> <id>Deliberate</id> <message>this exception was created by the throw instruction</message> </ex> </operand> </instr> <exception> <instr> <type>xslt</type> <operator>/xbin/test/xunit/data/exceptionformat.xsl</operator> <operand>this:exception</operand> <target>this:response</target> </instr> </exception> </seq> </idoc> Canonical Document ReferenceA Number of document types have been described in the DPML Guide. These canonical document types are defined here. URIA canonical URI document is used to represent a single URI reference. It is used
in the curi data type. It contains a root element of <uri>http://www.1060.org/index.html</uri>
XPathA canonical XPath document is used to represent a single XPath statement. It is used
in the xpatheval instruction. It contains a root element of <xpath>/a/b/*</xpath>
BooleanA canonical Boolean document is used to represent a boolean state of true or false. It
is expected as the target in a conditional instruction for both <b>t</b>
ExceptionA canonical Exception document is generated by the system when an exceptional situation
arises. It is available to instructions in an exception handling block by using the
<ex>
<id>CANCELED_EVENT</id> <message>No horses</message> <callstack>??</callstack> <ex> <id>BROKEN_LEG</id> <message>Fell going over a jump</message> <callstack>??</callstack> </ex> </ex>
|
||||||||||||||||||||||||||||||||||
|
© 2003,2004, 1060® Research Limited
1060 registered trademark, NetKernel trademark of 1060 Research Limited
|
||||||||||||||||||||||||||||||||||