public static Element[] toElementArray(Document doc,Object o) throws PageException {
  if (o instanceof Node[]) {
    Node[] nodes=(Node[])o;
    if (_isAllOfSameType(nodes,Node.ELEMENT_NODE))     return (Element[])nodes;
    Element[] elements=new Element[nodes.length];
    for (int i=0; i < nodes.length; i++) {
      elements[i]=toElement(doc,nodes[i]);
    }
    return elements;
  }
 else   if (o instanceof Collection) {
    Collection coll=(Collection)o;
    Iterator<Object> it=coll.valueIterator();
    List<Element> elements=new ArrayList<Element>();
    while (it.hasNext()) {
      elements.add(toElement(doc,it.next()));
    }
    return elements.toArray(new Element[elements.size()]);
  }
  Node[] nodes=_toNodeArray(doc,o);
  if (nodes != null)   return toElementArray(doc,nodes);
  try {
    return new Element[]{toElement(doc,o)};
  }
 catch (  ExpressionException e) {
    throw new XMLException("can't cast Object of type " + Caster.toClassName(o) + " to a XML Element Array");
  }
}

public static Element [ ] toElementArray ( Document doc , Object o ) throws PageException { if ( o instanceof Node [ ] ) { Node [ ] nodes = ( Node [ ] ) o ; if ( _isAllOfSameType ( nodes , Node . ELEMENT_NODE ) ) return ( Element [ ] ) nodes ; Element [ ] elements = new Element [ nodes . length ] ; for ( int i = 0 ; i < nodes . length ; i ++ ) { elements [ i ] = toElement ( doc , nodes [ i ] ) ; } return elements ; } else if ( o instanceof Collection ) { Collection coll = ( Collection ) o ; Iterator < Object > it = coll . valueIterator ( ) ; List < Element > elements = new ArrayList < Element > ( ) ; while ( it . hasNext ( ) ) { elements . add ( toElement ( doc , it . next ( ) ) ) ; } return elements . toArray ( new Element [ elements . size ( ) ] ) ; } Node [ ] nodes = _toNodeArray ( doc , o ) ; if ( nodes != null ) return toElementArray ( doc , nodes ) ; try { return new Element [ ] { toElement ( doc , o ) } ; } catch ( ExpressionException e ) { throw new XMLException ( "can't cast Object of type " + Caster . toClassName ( o ) + " to a XML Element Array" ) ; } }
casts a value to a xml element array
