public Iterator getChildAxisIterator(Object o) { if (isElement(o) || (o instanceof Document)) { return new IndexIterator(o, 0, ((ParentNode)o).getChildCount()) { public Object get(Object o, int i) { return ((ParentNode)o).getChild(i); } }; } return JaxenConstants.EMPTY_ITERATOR; }
/** * gets molecule context for spectrum. In simple documents we assume that * molecules will occur as siblings of spectrum elements. There may be * several spectrums but only one molecule is allowed. * * @return the sibling molecule or null. * @throws RuntimeException * if there are duplicate sibling molecules */ public CMLMolecule getSiblingMolecule() { CMLMolecule molecule = null; ParentNode parent = this.getParent(); if (parent != null) { for (int i = 0; i < parent.getChildCount(); i++) { Node node = parent.getChild(i); if (node instanceof CMLMolecule) { if (molecule != null) { throw new RuntimeException("duplicate sibling molecules"); } molecule = (CMLMolecule) node; } } } return molecule; }
private void writeNode(Node node, StringBuilder stringBuilder) { if (node instanceof ParentNode) { ParentNode parentNode = (ParentNode) node; Element mentionElement = new Element((Element)node); if(mentionElement.getLocalName().equals(TrConstants.FormatInfo.MENTION)){ stringBuilder.append('@'); } for (int childIndex = 0; childIndex < parentNode.getChildCount(); childIndex++) { writeNode(parentNode.getChild(childIndex), stringBuilder); } } else if (node instanceof Text) { Text text = (Text) node; stringBuilder.append(text.getValue()); } } }
private ChildAxisIterator(XOMNodeWrapper start, boolean downwards, boolean forwards, NodeTest test) { this.forwards = forwards; if (test == AnyNodeTest.getInstance()) { test = null; } nodeTest = test; commonParent = downwards ? start : start.getParent(); par = (ParentNode) commonParent.node; if (downwards) { ix = (forwards ? 0 : par.getChildCount()); } else { // find the start node among the list of siblings ix = par.indexOf(start.node); if (forwards) ix++; } cursor = ix; if (!downwards && !forwards) ix--; }
private NodeInfo advance() { Node nextChild; do { if (forwards) { if (cursor == par.getChildCount()) return null; nextChild = par.getChild(cursor++); } else { // backwards if (cursor == 0) return null; nextChild = par.getChild(--cursor); } } while (nextChild instanceof DocType); // DocType is not an XPath node; can occur for /child::node() NodeInfo curr = makeWrapper(nextChild, docWrapper, commonParent, ix); ix += (forwards ? 1 : -1); return curr; }
private ChildAxisIterator(XOMNodeWrapper start, boolean downwards, boolean forwards, NodeTest test) { this.forwards = forwards; if (test == AnyNodeTest.getInstance()) { test = null; } nodeTest = test; commonParent = downwards ? start : start.getParent(); par = (ParentNode) commonParent.node; if (downwards) { ix = (forwards ? 0 : par.getChildCount()); } else { // find the start node among the list of siblings ix = par.indexOf(start.node); if (forwards) ix++; } cursor = ix; if (!downwards && !forwards) ix--; }
private ChildAxisIterator(XOMNodeWrapper start, boolean downwards, boolean forwards, NodeTest test) { this.start = start; this.downwards = downwards; this.forwards = forwards; if (test == AnyNodeTest.getInstance()) test = null; nodeTest = test; position = 0; commonParent = downwards ? start : (XOMNodeWrapper) start.getParent(); par = (ParentNode) commonParent.node; if (downwards) { ix = (forwards ? 0 : par.getChildCount()); } else { // find the start node among the list of siblings // ix = start.getSiblingPosition(); ix = par.indexOf(start.node); if (forwards) ix++; } cursor = ix; if (!downwards && !forwards) ix--; }
private NodeInfo advance() { Node nextChild; do { if (forwards) { if (cursor == par.getChildCount()) { return null; } nextChild = par.getChild(cursor++); } else { // backwards if (cursor == 0) { return null; } nextChild = par.getChild(--cursor); } } while (nextChild instanceof DocType); // DocType is not an XPath node; can occur for /child::node() NodeInfo curr = makeWrapper(nextChild, docWrapper, commonParent, ix); ix += forwards ? 1 : -1; return curr; }
private NodeInfo advance() { Node nextChild; do { if (forwards) { if (cursor == par.getChildCount()) { return null; } nextChild = par.getChild(cursor++); } else { // backwards if (cursor == 0) { return null; } nextChild = par.getChild(--cursor); } } while (nextChild instanceof DocType); // DocType is not an XPath node; can occur for /child::node() NodeInfo curr = makeWrapper(nextChild, docWrapper, commonParent, ix); ix += forwards ? 1 : -1; return curr; }
/** * get next sibling. * * @author Eliotte Rusty Harold * @param current * may be null * @return following sibling or null */ public static Node getFollowingSibling(Node current) { Node node = null; if (current != null) { ParentNode parent = current.getParent(); if (parent != null) { int index = parent.indexOf(current); if (index + 1 < parent.getChildCount()) { node = parent.getChild(index + 1); } } } return node; }
/** * gets the element that is next or child to the join, depending * on moleculeRefs2 * * @return */ public CMLElement getChildOrNext() { if (getMoleculeRefs2Attribute().getValue().equals(PARENT_S + " " + CHILD_S)) { if (getChildCount() > 0) return (CMLElement) getChild(0); } else if (getMoleculeRefs2Attribute().getValue().equals(PREVIOUS_S + " " + NEXT_S)) { ParentNode parent = getParent(); int position = getParent().indexOf(this); if (position == parent.getChildCount() - 1) return null; return (CMLElement) parent.getChild(position + 1); } return null; }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
public XOMNodeWrapper getNextSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } int count = parenti.getChildCount(); if (index != -1) { if ((index + 1) < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } else { return null; } } index = parenti.indexOf(node); if (index + 1 < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } return null; }
/** * Get the following node in an iteration of descendants * * @param start the start node * @param anchor the node marking the root of the subtree within which navigation takes place (may be null) * @return the next node in document order after the start node, excluding attributes and namespaces */ private static Node getSuccessorNode(Node start, Node anchor) { if (start.getChildCount() > 0) { return start.getChild(0); } if (start == anchor) { return null; } Node p = start; while (true) { ParentNode q = p.getParent(); if (q == null) { return null; } int i = q.indexOf(p) + 1; // TODO: inefficient if a node has a large number of children if (i < q.getChildCount()) { return q.getChild(i); } if (q == anchor) { return null; } p = q; } }
public SteppingNode getNextSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } int count = parenti.getChildCount(); if (index != -1) { if ((index + 1) < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } else { return null; } } index = parenti.indexOf(node); if (index + 1 < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } return null; }
public XOMNodeWrapper getNextSibling() { ParentNode parenti = node.getParent(); if (parenti == null) { return null; } int count = parenti.getChildCount(); if (index != -1) { if ((index + 1) < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } else { return null; } } index = parenti.indexOf(node); if (index + 1 < count) { return makeWrapper(parenti.getChild(index + 1), docWrapper, parent, index + 1); } return null; }
for (int i=node.getChildCount(); --i >= 0; ) { Node child = node.getChild(i); if (child instanceof Element) { // recursively walk the tree
for (int i=node.getChildCount(); --i >= 0; ) { Node child = node.getChild(i); if (child instanceof Element) { // recursively walk the tree