in src/main/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java [300:346]
public String asPath() {
if (id != null) {
return "id('" + escape(id) + "')";
}
final StringBuilder buffer = new StringBuilder();
if (parent != null) {
buffer.append(parent.asPath());
}
if (node instanceof Element) {
// If the parent pointer is not a JDOMNodePointer, it is
// the parent's responsibility to produce the node test part
// of the path
if (parent instanceof JDOMNodePointer) {
if (buffer.length() == 0 || buffer.charAt(buffer.length() - 1) != '/') {
buffer.append('/');
}
final String nsURI = getNamespaceURI();
final String ln = getLocalName(node);
if (nsURI == null) {
buffer.append(ln);
buffer.append('[');
buffer.append(getRelativePositionByQName()).append(']');
} else {
final String prefix = getNamespaceResolver().getPrefix(nsURI);
if (prefix != null) {
buffer.append(prefix);
buffer.append(':');
buffer.append(ln);
buffer.append('[');
buffer.append(getRelativePositionByQName());
} else {
buffer.append("node()");
buffer.append('[');
buffer.append(getRelativePositionOfElement());
}
buffer.append(']');
}
}
} else if (node instanceof Text || node instanceof CDATA) {
buffer.append("/text()");
buffer.append('[').append(getRelativePositionOfTextNode()).append(']');
} else if (node instanceof ProcessingInstruction) {
buffer.append("/processing-instruction(\'").append(((ProcessingInstruction) node).getTarget()).append("')");
buffer.append('[').append(getRelativePositionOfPI()).append(']');
}
return buffer.toString();
}