6. A computer program product for processing a query comprising a non-transitory computer-readable medium storing a computer readable program, wherein the computer readable program, when executed by a processor on a computer, causes the computer to: receive the query, wherein the query is formed by one or more paths, and wherein each path includes one or more steps; receive a hierarchical document including one or more document nodes; and while processing the query and traversing the hierarchical document, constructing a structure, wherein the structure includes structure nodes, and wherein each of the structure nodes includes a next step in a path of the query, a level for a next step instance, a parent step instance identifier of a next step instance, and a matched step instance identifier when a match is found; construct one or more extraction entries by traversing the structure bottom up, starting from a last structure node and continuing up to a root node of the structure while propagating up parent step instance identifier information to form a step instance ancestor path, wherein each of the one or more extraction entries includes a step instance match candidate identifying a document node and the step instance ancestor path for the document node; and construct one or more tuples using the one or more extraction entries by associating the step instance match candidate from one of the one or more extraction entries with the step instance match candidate from at least one of the one or more other extraction entries.
6. A computer program product for processing a query comprising a non-transitory computer-readable medium storing a computer readable program, wherein the computer readable program, when executed by a processor on a computer, causes the computer to: receive the query, wherein the query is formed by one or more paths, and wherein each path includes one or more steps; receive a hierarchical document including one or more document nodes; and while processing the query and traversing the hierarchical document, constructing a structure, wherein the structure includes structure nodes, and wherein each of the structure nodes includes a next step in a path of the query, a level for a next step instance, a parent step instance identifier of a next step instance, and a matched step instance identifier when a match is found; construct one or more extraction entries by traversing the structure bottom up, starting from a last structure node and continuing up to a root node of the structure while propagating up parent step instance identifier information to form a step instance ancestor path, wherein each of the one or more extraction entries includes a step instance match candidate identifying a document node and the step instance ancestor path for the document node; and construct one or more tuples using the one or more extraction entries by associating the step instance match candidate from one of the one or more extraction entries with the step instance match candidate from at least one of the one or more other extraction entries. 9. The computer program product of claim 6 , wherein the structure is a LookingFor structure.