/** * Get a character string that uniquely identifies this node. * Note: a.isSameNode(b) if and only if generateId(a)==generateId(b) * * @param buffer a buffer to contain a string that uniquely identifies this node, across all * documents */ public void generateId(FastStringBuffer buffer) { Navigator.appendSequentialKey(this, buffer, true); }
/** * Determine the relative position of this node and another node, in document order, * distinguishing whether the first node is a preceding, following, descendant, ancestor, * or the same node as the second. * <p/> * The other node must always be in the same tree; the effect of calling this method * when the two nodes are in different trees is undefined. If either node is a namespace * or attribute node, the method should throw UnsupportedOperationException. * * @param other The other node, whose position is to be compared with this * node * @return {@link net.sf.saxon.om.AxisInfo#PRECEDING} if this node is on the preceding axis of the other node; * {@link net.sf.saxon.om.AxisInfo#FOLLOWING} if it is on the following axis; {@link net.sf.saxon.om.AxisInfo#ANCESTOR} if the first node is an * ancestor of the second; {@link net.sf.saxon.om.AxisInfo#DESCENDANT} if the first is a descendant of the second; * {@link net.sf.saxon.om.AxisInfo#SELF} if they are the same node. * @throws UnsupportedOperationException if either node is an attribute or namespace * @since 9.5 */ public int comparePosition(NodeInfo other) { return Navigator.comparePosition(this, other); }
/** * Copy this node to a given outputter * @param out the Receiver to which the node should be copied * @param copyOptions a selection of the options defined in {@link net.sf.saxon.om.CopyOptions} * @param locationId Identifies the location of the instruction */ public void copy(Receiver out, int copyOptions, Location locationId) throws XPathException { Navigator.copy(this, out, copyOptions, locationId); }
/** * Get an absolute XPath expression that identifies a given node within its document * * @param node the node whose path is required. If null is supplied, * an empty string is returned - this fact is used in making a recursive call * for a parentless node. * @return a path expression that can be used to retrieve the node */ public static String getPath(NodeInfo node) { return getPath(node, null); }
/** * Return an iteration over the nodes reached by the given axis from this node * * @param axisNumber the axis to be searched, e.g. Axis.CHILD or Axis.ANCESTOR * @param nodeTest A pattern to be matched by the returned nodes * @return a SequenceIterator that scans the nodes reached by the axis in turn. */ /*@NotNull*/ public AxisIterator iterateAxis(byte axisNumber, /*@NotNull*/ NodeTest nodeTest) { switch (axisNumber) { case AxisInfo.ANCESTOR_OR_SELF: case AxisInfo.DESCENDANT_OR_SELF: case AxisInfo.SELF: return Navigator.filteredSingleton(this, nodeTest); case AxisInfo.ANCESTOR: case AxisInfo.ATTRIBUTE: case AxisInfo.CHILD: case AxisInfo.DESCENDANT: case AxisInfo.FOLLOWING: case AxisInfo.FOLLOWING_SIBLING: case AxisInfo.NAMESPACE: case AxisInfo.PARENT: case AxisInfo.PRECEDING: case AxisInfo.PRECEDING_SIBLING: case AxisInfo.PRECEDING_OR_ANCESTOR: return EmptyIterator.OfNodes.THE_INSTANCE; default: throw new IllegalArgumentException("Unknown axis number " + axisNumber); } }
/** * Get a character string that uniquely identifies this node and that collates nodes * into document order * * @param node the node whose unique identifier is reuqired * @param sb a buffer to which the unique identifier will be appended * @param addDocNr true if a unique document number is to be included in the information */ public static void appendSequentialKey(/*@NotNull*/ SiblingCountingNode node, /*@NotNull*/ FastStringBuffer sb, boolean addDocNr) { if (addDocNr) { sb.append('w'); sb.append(Long.toString(node.getTreeInfo().getDocumentNumber())); } if (node.getNodeKind() != Type.DOCUMENT) { NodeInfo parent = node.getParent(); if (parent != null) { appendSequentialKey((SiblingCountingNode) parent, sb, false); } if (node.getNodeKind() == Type.ATTRIBUTE) { sb.append('A'); } } sb.append(alphaKey(node.getSiblingPosition())); }
return node.getDisplayName(); } else { pre = getPath(parent, context); if (pre.equals("/")) { return '/' + node.getDisplayName(); } else { return pre + '/' + node.getDisplayName() + (streamed ? "" : "[" + getNumberSimple(node, context) + "]"); return getPath(parent, context) + "/@" + node.getDisplayName(); case Type.TEXT: pre = getPath(parent, context); return (pre.equals("/") ? "" : pre) + "/text()" + (streamed ? "" : "[" + getNumberSimple(node, context) + "]"); pre = getPath(parent, context); return (pre.equals("/") ? "" : pre) + "/comment()" + (streamed ? "" : "[" + getNumberSimple(node, context) + "]"); pre = getPath(parent, context); return (pre.equals("/") ? "" : pre) + "/processing-instruction()" + (streamed ? "" : "[" + getNumberSimple(node, context) + "]"); return getPath(parent, context) + "/namespace::" + test; default: return "";
if (!Navigator.haveSameName(n1, n2)) { explain(config, "element names differ: " + NameOfNode.makeName(n1).getStructuredQName().getEQName() + " != " + NameOfNode.makeName(n2).getStructuredQName().getEQName(), flags, n1, n2); if (!Navigator.haveSameName(n1, n2)) { explain(config, "attribute names differ: " + NameOfNode.makeName(n1).getStructuredQName().getEQName() + Navigator.getPath(n1) + ", " + Navigator.getPath(n2) + "): " + message, flags, n1, n2);
/** * Get the Base URI for the node, that is, the URI used for resolving a relative URI contained * in the node. This will be the same as the System ID unless xml:base has been used. * * @return the base URI of the node */ /*@Nullable*/ public String getBaseURI() { return Navigator.getBaseURI(this); }
return getNumberSimple(node, context); target.iterateAxis(AxisInfo.PRECEDING_SIBLING, getNodeTestForPattern(count));
/** * Determine the relative position of this node and another node, in document order. * The other node will always be in the same document. * * @param other The other node, whose position is to be compared with this node * @return -1 if this node precedes the other node, +1 if it follows the other * node, or 0 if they are the same node. (In this case, isSameNode() will always * return true, and the two nodes will produce the same result for generateId()) */ public final int compareOrder(/*@NotNull*/ NodeInfo other) { if (other instanceof NamespaceNode) { return 0 - other.compareOrder(this); } long a = getSequenceNumber(); long b = ((NodeImpl) other).getSequenceNumber(); if (a == -1L || b == -1L) { // Nodes added by XQuery Update do not have sequence numbers return Navigator.compareOrder(this, (NodeImpl) other); } return Long.compare(a, b); }
public AttributeLocation(NodeInfo element, StructuredQName attributeName) { this.systemId = element.getSystemId(); this.lineNumber = element.getLineNumber(); this.columnNumber = element.getColumnNumber(); this.elementName = Navigator.getNodeName(element); this.attributeName = attributeName; }
filter = getNodeTestForPattern(count); } else if (from.getUType() == UType.ELEMENT && count.getUType() == UType.ELEMENT) { filter = NodeKindTest.ELEMENT;
/** * Get an absolute XPath expression that identifies a given node within its document * * @param node the node whose path is required. If null is supplied, * an empty string is returned - this fact is used in making a recursive call * for a parentless node. * @return a path expression that can be used to retrieve the node */ public static String getPath(NodeInfo node) { return getPath(node, null); }
/** * Return an iteration over the nodes reached by the given axis from this node * * @param axisNumber the axis to be searched, e.g. Axis.CHILD or Axis.ANCESTOR * @param nodeTest A pattern to be matched by the returned nodes * @return a SequenceIterator that scans the nodes reached by the axis in turn. */ /*@NotNull*/ public AxisIterator iterateAxis(byte axisNumber, /*@NotNull*/ NodeTest nodeTest) { switch (axisNumber) { case AxisInfo.ANCESTOR_OR_SELF: case AxisInfo.DESCENDANT_OR_SELF: case AxisInfo.SELF: return Navigator.filteredSingleton(this, nodeTest); case AxisInfo.ANCESTOR: case AxisInfo.ATTRIBUTE: case AxisInfo.CHILD: case AxisInfo.DESCENDANT: case AxisInfo.FOLLOWING: case AxisInfo.FOLLOWING_SIBLING: case AxisInfo.NAMESPACE: case AxisInfo.PARENT: case AxisInfo.PRECEDING: case AxisInfo.PRECEDING_SIBLING: case AxisInfo.PRECEDING_OR_ANCESTOR: return EmptyIterator.OfNodes.THE_INSTANCE; default: throw new IllegalArgumentException("Unknown axis number " + axisNumber); } }
/** * Get a character string that uniquely identifies this node and that collates nodes * into document order * * @param node the node whose unique identifier is reuqired * @param sb a buffer to which the unique identifier will be appended * @param addDocNr true if a unique document number is to be included in the information */ public static void appendSequentialKey(/*@NotNull*/ SiblingCountingNode node, /*@NotNull*/ FastStringBuffer sb, boolean addDocNr) { if (addDocNr) { sb.append('w'); sb.append(Long.toString(node.getTreeInfo().getDocumentNumber())); } if (node.getNodeKind() != Type.DOCUMENT) { NodeInfo parent = node.getParent(); if (parent != null) { appendSequentialKey((SiblingCountingNode) parent, sb, false); } if (node.getNodeKind() == Type.ATTRIBUTE) { sb.append('A'); } } sb.append(alphaKey(node.getSiblingPosition())); }
return node.getDisplayName(); } else { pre = getPath(parent, context); if (pre.equals("/")) { return '/' + node.getDisplayName(); } else { return pre + '/' + node.getDisplayName() + (streamed ? "" : '[' + getNumberSimple(node, context) + ']'); return getPath(parent, context) + "/@" + node.getDisplayName(); case Type.TEXT: pre = getPath(parent, context); return (pre.equals("/") ? "" : pre) + "/text()" + (streamed ? "" : '[' + getNumberSimple(node, context) + ']'); pre = getPath(parent, context); return (pre.equals("/") ? "" : pre) + "/comment()" + (streamed ? "" : '[' + getNumberSimple(node, context) + ']'); pre = getPath(parent, context); return (pre.equals("/") ? "" : pre) + "/processing-instruction()" + (streamed ? "" : '[' + getNumberSimple(node, context) + ']'); return getPath(parent, context) + "/namespace::" + test; default: return "";
if (!Navigator.haveSameName(n1, n2)) { explain(config, "element names differ: " + NameOfNode.makeName(n1).getStructuredQName().getEQName() + " != " + NameOfNode.makeName(n2).getStructuredQName().getEQName(), flags, n1, n2); if (!Navigator.haveSameName(n1, n2)) { explain(config, "attribute names differ: " + NameOfNode.makeName(n1).getStructuredQName().getEQName() + Navigator.getPath(n1) + ", " + Navigator.getPath(n2) + "): " + message, flags, n1, n2);
/** * Get the base URI of this processing instruction node. */ public String getBaseURI() { return Navigator.getBaseURI(this); }
return getNumberSimple(node, context); target.iterateAxis(AxisInfo.PRECEDING_SIBLING, getNodeTestForPattern(count));