NodeModel
instead.public class NodeListModel extends java.lang.Object implements TemplateHashModel, TemplateMethodModel, TemplateCollectionModel, TemplateSequenceModel, TemplateScalarModel
getAsString()
will render all contained nodes as XML fragment,
exec(List)
provides full XPath functionality implemented on top of
the Jaxen library,get(String)
provides node traversal, copying and filtering - somewhat
less expressive than XPath, however it does not require the external library and
it evaluates somewhat fasterTemplateCollectionModel
allows to iterate the contained node list, andTemplateSequenceModel
allows to access the contained nodes by index and query the node count.Note: There is a JDOM independent re-implementation of this class:
freemarker.ext.xml.NodeListModel
EMPTY_STRING
NOTHING
Constructor and Description |
---|
NodeListModel(org.jdom.Document document)
Deprecated.
Creates a node list that holds a single
Document node. |
NodeListModel(org.jdom.Element element)
Deprecated.
Creates a node list that holds a single
Element node. |
NodeListModel(java.util.List nodes)
Deprecated.
Creates a node list that holds a list of nodes.
|
NodeListModel(java.util.List nodes,
boolean copy)
Deprecated.
Creates a node list that holds a list of nodes.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
exec(java.util.List arguments)
Deprecated.
Applies an XPath expression to the node list and returns the resulting node list.
|
TemplateModel |
get(int i)
Deprecated.
Retrieves the i-th element of the node list.
|
TemplateModel |
get(java.lang.String key)
Deprecated.
Provides node list traversal as well as special functions: filtering by name,
filtering by node type, shallow-copying, and duplicate removal.
|
java.lang.String |
getAsString()
Deprecated.
This method returns the string resulting from concatenation
of string representations of its nodes.
|
boolean |
isEmpty()
Deprecated.
Returns true if this model contains no nodes.
|
TemplateModelIterator |
iterator()
Deprecated.
Retrieves a template model iterator that is used to iterate over
the elements in this collection.
|
static void |
main(java.lang.String[] args)
Deprecated.
Loads a template from a file passed as the first argument, loads an XML
document from the standard input, passes it to the template as variable
document and writes the result of template processing to
standard output.
|
void |
registerNamespace(java.lang.String prefix,
java.lang.String uri)
Deprecated.
Registers an XML namespace with this node list.
|
int |
size()
Deprecated.
|
public NodeListModel(org.jdom.Document document)
Document
node.public NodeListModel(org.jdom.Element element)
Element
node.public NodeListModel(java.util.List nodes)
nodes
- the list of nodes this template should hold. The created template
will copy the passed nodes list, so changes to the passed list will not affect
the model.public NodeListModel(java.util.List nodes, boolean copy)
nodes
- the list of nodes this template should hold.copy
- if true, the created template will copy the passed nodes list,
so changes to the passed list will not affect the model. If false, the model
will reference the passed list and will sense changes in it, although no
operations on the list will be synchronized.public boolean isEmpty()
isEmpty
in interface TemplateHashModel
public java.lang.String getAsString() throws TemplateModelException
getAsString
in interface TemplateScalarModel
TemplateModelException
public TemplateModel get(java.lang.String key) throws TemplateModelException
exec(List)
method, it does not require the external Jaxen
library to be present at run time. Below are listed the recognized keys.
In key descriptions, "applicable to this-and-that node type" means that if
a key is applied to a node list that contains a node of non-applicable type
a TemplateMethodModel will be thrown. However, you can use _ftype
key to explicitly filter out undesired node types prior to applying the
restricted-applicability key. Also "current nodes" means nodes contained in this
set.
registerNamespace(String, String)
method.
get
in interface TemplateHashModel
key
- a key that identifies a required set of nodesTemplateModelException
public TemplateModelIterator iterator()
TemplateCollectionModel
iterator
in interface TemplateCollectionModel
public TemplateModel get(int i) throws TemplateModelException
get
in interface TemplateSequenceModel
null
if
the index is out of bounds. Note that a null
value is
interpreted by FreeMarker as "variable does not exist", and accessing
a missing variables is usually considered as an error in the FreeMarker
Template Language, so the usage of a bad index will not remain hidden.TemplateModelException
public int size()
size
in interface TemplateSequenceModel
public java.lang.Object exec(java.util.List arguments) throws TemplateModelException
exec
in interface TemplateMethodModel
arguments
- the list of arguments. Must contain exactly one string that is
the XPath expression you wish to apply. The XPath expression can use any namespace
prefixes that were defined using the registerNamespace(String, String)
method or the nodelist._registerNamespace(prefix, uri)
expression in the
template.TemplateModelException
public void registerNamespace(java.lang.String prefix, java.lang.String uri)
get(String)
method from this node list and all other
node lists that are derived from this node list. Use the
nodelist["prefix:localname"] or the
nodelist["@prefix:localname"] syntax to reach elements and
attributes whose names are namespace-scoped. Note that the namespace
prefix need not match the actual prefix used by the XML document itself
since namespaces are compared solely by their URI. You can also register
namespaces during template evaluation using the
nodelist._registerNamespace(prefix, uri) syntax in the template.
This mechanism is completely independent from the namespace declarations
in the XML document itself; its purpose is to give you an easy way
to refer to namespace-scoped elements in get(String)
and
in XPath expressions passed to exec(List)
. Note also that
the namespace prefix registry is shared among all node lists that
are created from a single node list - modifying the registry in one
affects all others as well. If you want to obtain a namespace
"detached" copy of the node list, use the _copy
key on
it (or call nodeList.get("_copy")
directly from your
Java code. The returned node list has all the namespaces that the
original node list has, but they can be manipulated independently
thereon.public static void main(java.lang.String[] args) throws java.lang.Exception
java.lang.Exception