}
private HTMLNode processPrevNode(HTMLNode root, List<HTMLNode> anchors, int i) {
if (i < 0 || i >= anchors.size())
return root;
HTMLNode node = anchors.get(i);
HTMLNode prevNode = anchors.get(i - 1);
String path = getIndexPath(node);
String prevPath = getIndexPath(prevNode);
String commonPath = getCommonIndexPath(path, prevPath);
try {
HTMLNode commonNode = getNodeByIndex(root, commonPath);
path = path.substring(commonPath.length());
int idx = path.indexOf('.', 1);
// path = path.substring(0, idx);
if (idx > 0) {
path = path.substring(1, idx);
} else {
if (path.charAt(0) == '.')
path = path.substring(1);
}
// if(idx > 1) path = path.substring(2, idx);
// if(path.charAt(0) == '.') path = path.substring(1);
// if(path.trim().isEmpty()) return root;
idx = Integer.parseInt(path);
HTMLNode newCommonNode = new NodeImpl(commonNode.getValue(), commonNode.getName(),
TypeToken.TAG);
List<HTMLNode> children = commonNode.getChildren();
for (i = idx; i < children.size(); i++) {
newCommonNode.addChild(children.get(i));
// children.get(i).setParent(newCommonNode);
}
return newCommonNode;
} catch (Exception e) {
StringBuilder builder = new StringBuilder();