The fp:resource
element with it's mandatory id
attribute, is for defining a file you would like to read and/or write to. It takes a series of configuration elements as children.
The list of valid child elements is:
fp:resource-file (mandatory) -
The path to a file you want to work with
fp:resource-node (mandatory) -
An XPath to select the Node in your file that you want to work with
fp:default-mode (defaults to replace if not present) -
The default mode you want to use when writing your Nodes, replace
replaces the selected Node, insert-before
and inser-after
create a new Node, with the same name as the selected, and inserts before or after.
None of the above tags have any relevance outside of the fp:resource-file
.
You can use as many fp:resource-file
elements as you have unique files to work with, each one should have a unique id
attribute, this is what you use to refer to them. ie. the FP TagLib can work with multiple files at the same time.
Errors are flagged by placing an fp-error
attribute into the parent of the fp:resource-file
tag, with a value that is an IDREF pointing to an fp-error
element in your document root.
The fp:read
element reads TextNodes or Nodes from the specified fp:resource
into it's parent Element using a relative XPath. It has several mandatory attributes.
The list of valid attributes is:
from (mandatory) -
The id
of the fp:resource
you want to read
select (mandatory) -
An XPath (relative to fp:resource-node
) to select the Node(s) in the fp:resource
you want to read
as (defaults to string) -
The way you want to read the Node(s) selected by your XPath. The default, string
reads all of the TextNodes that are children of the selected Node(s); node
reads all of the selected Nodes as deep cloned XML.
It is safe to use an XPath in your fp:read
element select
attribute that selects multiple Nodes.
If the parent of an fp:read
element is an fp:write
element, the output of the fp:read
element goes to the fp:write
element and is written to file. Otherwise the output goes to the user, like any other TagLib.
The fp:write
element writes TextNodes or Nodes to the specified fp:resource
at the location specified by it's relative XPath. It has several mandatory attributes.
The list of valid attributes is:
to (mandatory) -
The id
of the fp:resource
you want to write
select (mandatory) -
An XPath (relative to fp:resource-node
) to select the Node in the fp:resource
you want to write
as (defaults to string) -
The way you want to write the Node selected by your XPath. The default, string
overwrites all of the TextNodes that are children of the selected Node with the text content of the fp:write
element; node
replaces the selected Node with the content of the fp:write
element as XML.
It is not safe to use an XPath in your fp:write
element select
attribute that selects multiple Nodes.
Only FP or other TagLib Tags can be used as child elements of the fp:write
element. To do otherwise, causes compilation errors that can be difficult to track down. There may be a solution to this
The fp:write
element may only use a simplified form of XPath in it's select
attribute, one that is just a simple "path/to/node", because the TagLib has to be able to construct any Nodes you ask for and it can only interpret the simplest case. ie. you can use an XPath like this/is/an/xpath/to/nowhere
and the data will be written with all the intervening elements whether they currently exist or not, but an XPath like title/*
will not work. (This is different from fp:read
's behaviour).
The fp:if-post
element allows simple logic, based on the HTTP Method of the incoming request.
Any child elements of the fp:if-post
element are ignored during GET, HEAD, PUT and DELETE requests.
The fp:if-get
element allows simple logic, based on the HTTP Method of the incoming request.
Any child elements of the fp:if-get
element are ignored during POST, HEAD, PUT and DELETE requests.
The fp:redirect
element can be used to redirect the user to another URL when two conditions have been met, that this was a POST Request, and there were no errors generated by any of the other FP Tags.
The value of the fp:redirect
element, is the URL you want users to go to, it should accept relative, root and absolute addressed URLs.