in src/main/java/org/apache/commons/jxpath/ri/model/jdom/JDOMNodePointer.java [637:695]
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 = JDOMNodePointer.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());
buffer.append(']');
}
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();
}