7. A computer program product for processing a query comprising a computer useable medium for 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: construct a LookingFor structure, wherein the LookingFor structure includes Looking For nodes, wherein each Looking For node includes a next step in a path of the query, at least one of a minimum level and an absolute level for a next step instance, a level of an end event, a parent step instance identifier of a next step instance, and a matched step instance identifier when a match is found, wherein a document node in the hierarchical document that is described by a step in the query is called a step instance candidate, and wherein a step instance candidate is assigned a unique identifier called a step instance identifier; construct one or more extraction entries constructed from the LookingFor structure, wherein each extraction entry includes a step instance match candidate identifying a document node and a 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, wherein the constructing of the one or more tuples includes determining which step instance match candidates are to be paired, in which order the step instance match candidates are to be paired to form tuples, and which ancestors are to be compared for each pair of step instance match candidates.
7. A computer program product for processing a query comprising a computer useable medium for 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: construct a LookingFor structure, wherein the LookingFor structure includes Looking For nodes, wherein each Looking For node includes a next step in a path of the query, at least one of a minimum level and an absolute level for a next step instance, a level of an end event, a parent step instance identifier of a next step instance, and a matched step instance identifier when a match is found, wherein a document node in the hierarchical document that is described by a step in the query is called a step instance candidate, and wherein a step instance candidate is assigned a unique identifier called a step instance identifier; construct one or more extraction entries constructed from the LookingFor structure, wherein each extraction entry includes a step instance match candidate identifying a document node and a 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, wherein the constructing of the one or more tuples includes determining which step instance match candidates are to be paired, in which order the step instance match candidates are to be paired to form tuples, and which ancestors are to be compared for each pair of step instance match candidates. 12. The computer program product of claim 7 , wherein when constructing an extraction entry, the computer readable program when executed on a computer causes the computer to: traverse the LookingFor structure bottom up, starting from a last LookingFor node and continuing up to a root node of the LookingFor structure while propagating up parent step instance identifiers to form a step instance ancestor path; store the a document node as the step instance match candidate in the extraction entry; and store an associated step instance ancestor path in the extraction entry.