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

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.

Constructor:
 public NodeListModel(Object nodes) 
    Creates a new NodeListModel, wrapping the passed nodes.
    Parameters:
    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.
    Throws:
    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 
      Deprecated!
    Evaluates an XPath expression on XML nodes in this model.
 public TemplateModel get(int index) 
      Deprecated!
    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 
      Deprecated!
    Returns a new NodeListModel containing the nodes that result from applying an operator to this model's nodes.
 public String getAsString() throws TemplateModelException 
      Deprecated!
    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 
      Deprecated!
 public String getNodeName() throws TemplateModelException 
      Deprecated!
 public String getNodeNamespace() throws TemplateModelException 
      Deprecated!
 public String getNodeType() throws TemplateModelException 
      Deprecated!
 public TemplateNodeModel getParentNode() throws TemplateModelException 
      Deprecated!
 public boolean isEmpty() 
      Deprecated!
    Returns true if this NodeListModel contains no nodes.
 public  void registerNamespace(String prefix,
    String uri) 
      Deprecated!
    Registers a namespace prefix-URI pair for subsequent use in #get(String) as well as for use in XPath expressions.
 public int size() 
      Deprecated!
    Returns the number of nodes in this model's nodelist.