Use a TreeWalker with the extractEdges() method.