/** * Creates a new Node named <code>name</code> and if a parent is supplied, adds * the newly created node as a child of the parent. * * @param parent the parent node or null if no parent * @param name the name of the node */ public Node(Node parent, Object name) { this(parent, name, new NodeList()); }
/** * Creates a new NodeList containing the same elements as the * original (but cloned in the case of Nodes). * * @return the clone */ @Override public Object clone() { NodeList result = new NodeList(size()); for (int i = 0; i < size(); i++) { Object next = get(i); if (next instanceof Node) { Node n = (Node) next; result.add(n.clone()); } else { result.add(next); } } return result; }
/** * Provides lookup of elements by non-namespaced name. * * @param name the name or shortcut key for nodes of interest * @return the nodes of interest which match name */ public NodeList getAt(String name) { NodeList answer = new NodeList(); for (Object child : this) { if (child instanceof Node) { Node childNode = (Node) child; Object temp = childNode.get(name); if (temp instanceof Collection) { answer.addAll((Collection) temp); } else { answer.add(temp); } } } return answer; }
/** * Provides lookup of elements by non-namespaced name. * * @param name the name or shortcut key for nodes of interest * @return the nodes of interest which match name */ public NodeList getAt(String name) { NodeList answer = new NodeList(); for (Iterator iter = iterator(); iter.hasNext();) { Object child = iter.next(); if (child instanceof Node) { Node childNode = (Node) child; Object temp = childNode.get(name); if (temp instanceof Collection) { answer.addAll((Collection) temp); } else { answer.add(temp); } } } return answer; }
/** * Provides lookup of elements by name. * * @param name the name of interest * @return the nodes matching name */ private NodeList getByName(String name) { NodeList answer = new NodeList(); for (Object child : children()) { if (child instanceof Node) { Node childNode = (Node) child; Object childNodeName = childNode.name(); if (childNodeName instanceof QName) { QName qn = (QName) childNodeName; if (qn.matches(name)) { answer.add(childNode); } } else if (name.equals(childNodeName)) { answer.add(childNode); } } } return answer; }
/** * Provides lookup of elements by QName. * * @param name the name or shortcut key for nodes of interest * @return the nodes of interest which match name */ public NodeList getAt(QName name) { NodeList answer = new NodeList(); for (Iterator iter = iterator(); iter.hasNext();) { Object child = iter.next(); if (child instanceof Node) { Node childNode = (Node) child; NodeList temp = childNode.getAt(name); answer.addAll(temp); } } return answer; }
@Override public Object getAttribute(final Object object, final String attribute) { NodeList nl = (NodeList) object; Iterator it = nl.iterator(); List result = new ArrayList(); while (it.hasNext()) { Node node = (Node) it.next(); result.add(node.attributes().get(attribute)); } return result; }
/** * Provides lookup of elements by QName. * * @param name the name or shortcut key for nodes of interest * @return the nodes of interest which match name */ public NodeList getAt(QName name) { NodeList answer = new NodeList(); for (Object child : this) { if (child instanceof Node) { Node childNode = (Node) child; NodeList temp = childNode.getAt(name); answer.addAll(temp); } } return answer; }
@Override public Object getProperty(Object object, String property) { if (object instanceof NodeList) { NodeList nl = (NodeList) object; return nl.getAt(property); } return super.getProperty(object, property); } };
NodeList nodeList = doc.getElementsByTagName("Morning"); Node node = nodeList.get("sunrise"); String sunrise = node.getValue();
/** * Provides lookup of elements by non-namespaced name. * * @param name the name or shortcut key for nodes of interest * @return the nodes of interest which match name */ public NodeList getAt(String name) { NodeList answer = new NodeList(); for (Iterator iter = iterator(); iter.hasNext();) { Object child = iter.next(); if (child instanceof Node) { Node childNode = (Node) child; Object temp = childNode.get(name); if (temp instanceof Collection) { answer.addAll((Collection) temp); } else { answer.add(temp); } } } return answer; }
/** * Provides lookup of elements by QName. * * @param name the QName of interest * @return the nodes matching name */ public NodeList getAt(QName name) { NodeList answer = new NodeList(); for (Object child : children()) { if (child instanceof Node) { Node childNode = (Node) child; Object childNodeName = childNode.name(); if (name.matches(childNodeName)) { answer.add(childNode); } } } return answer; }
/** * Provides lookup of elements by QName. * * @param name the name or shortcut key for nodes of interest * @return the nodes of interest which match name */ public NodeList getAt(QName name) { NodeList answer = new NodeList(); for (Iterator iter = iterator(); iter.hasNext();) { Object child = iter.next(); if (child instanceof Node) { Node childNode = (Node) child; NodeList temp = childNode.getAt(name); answer.addAll(temp); } } return answer; }
public Object getAttribute(final Object object, final String attribute) { NodeList nl = (NodeList) object; Iterator it = nl.iterator(); List result = new ArrayList(); while (it.hasNext()) { Node node = (Node) it.next(); result.add(node.attributes().get(attribute)); } return result; }
/** * Provides lookup of elements by QName. * * @param name the name or shortcut key for nodes of interest * @return the nodes of interest which match name */ public NodeList getAt(QName name) { NodeList answer = new NodeList(); for (Object child : this) { if (child instanceof Node) { Node childNode = (Node) child; NodeList temp = childNode.getAt(name); answer.addAll(temp); } } return answer; }
@Override public Object getProperty(Object object, String property) { if (object instanceof NodeList) { NodeList nl = (NodeList) object; return nl.getAt(property); } return super.getProperty(object, property); } };