Home » freemarker-2.3.13 » freemarker.ext.xml » [javadoc | source]
public class: NodeListModel [javadoc | source]

All Implemented Interfaces:
    TemplateMethodModel, TemplateSequenceModel, TemplateScalarModel, TemplateHashModel, TemplateNodeModel

Deprecated! Use - freemarker.ext.dom.NodeModel instead.

A data model adapter for three widespread XML document object model representations: W3C DOM, dom4j, and JDOM. The adapter automatically recognizes the used XML object model and provides a unified interface for it toward the template. The model provides access to all XML InfoSet features of the XML document and includes XPath support if it has access to the XPath- evaluator library Jaxen. The model's philosophy (which closely follows that of XML InfoSet and XPath) is as follows: it always wraps a list of XML nodes (the "nodelist"). The list can be empty, can have a single element, or can have multiple elements. Every operation applied to the model is applied to all nodes in its nodelist. You usually start with a single- element nodelist, usually the root element node or the document node of the XML tree. Additionally, the nodes can contain String objects as a result of certain evaluations (getting the names of elements, values of attributes, etc.)

Implementation note: If you are using W3C DOM documents built by the Crimson XML parser (or you are using the built-in JDK 1.4 XML parser, which is essentially Crimson), make sure you call setNamespaceAware(true) on the javax.xml.parsers.DocumentBuilderFactory instance used for document building even when your documents don't use XML namespaces. Failing to do so, you will experience incorrect behavior when using the documents wrapped with this model.

 public NodeListModel(Object nodes) 
    Creates a new NodeListModel, wrapping the passed nodes.
    nodes - you can pass it a single XML node from any supported document model, or a Java collection containing any number of nodes. Passing null is prohibited. To create an empty model, pass it an empty collection. If a collection is passed, all passed nodes must belong to the same XML object model, i.e. you can't mix JDOM and dom4j in a single instance of NodeListModel. The model itself doesn't check for this condition, as it can be time consuming, but will throw spurious ClassCastException s when it encounters mixed objects.
    IllegalArgumentException - if you pass null
Method from freemarker.ext.xml.NodeListModel Summary:
exec,   get,   get,   getAsString,   getChildNodes,   getNodeName,   getNodeNamespace,   getNodeType,   getParentNode,   isEmpty,   registerNamespace,   size
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from freemarker.ext.xml.NodeListModel Detail:
 public Object exec(List arguments) throws TemplateModelException 
    Evaluates an XPath expression on XML nodes in this model.
 public TemplateModel get(int index) 
    Selects a single node from this model's nodelist by its list index and returns a new NodeListModel containing that single node.
 public TemplateModel get(String key) throws TemplateModelException 
    Returns a new NodeListModel containing the nodes that result from applying an operator to this model's nodes.
 public String getAsString() throws TemplateModelException 
    Returns the string representation of the wrapped nodes. String objects in the nodelist are rendered as-is (with no XML escaping applied). All other nodes are rendered in the default XML serialization format ("plain XML"). This makes the model quite suited for use as an XML-transformation tool.
 public TemplateSequenceModel getChildNodes() throws TemplateModelException 
 public String getNodeName() throws TemplateModelException 
 public String getNodeNamespace() throws TemplateModelException 
 public String getNodeType() throws TemplateModelException 
 public TemplateNodeModel getParentNode() throws TemplateModelException 
 public boolean isEmpty() 
    Returns true if this NodeListModel contains no nodes.
 public  void registerNamespace(String prefix,
    String uri) 
    Registers a namespace prefix-URI pair for subsequent use in #get(String) as well as for use in XPath expressions.
 public int size() 
    Returns the number of nodes in this model's nodelist.