1. A method of labeling and querying a XML document on a device that includes processing circuitry comprising: inputting data from a XML tree structure; visiting a plurality of nodes in the XML tree structure by breath-first traversal in level order; assigning a label to each node in the plurality of nodes in a first level wherein the first label includes a integer value for the first level, and a unique number that is a sequential binary number; assigning a subsequent label using the processing circuitry to each node of the plurality of nodes on subsequent levels where the node is a child of a parent node in a previous level, wherein the subsequent label includes a subsequent integer value of the level of the node where the node exists and a subsequent unique number is created by concatenating a subsequent sequential binary number and a parent's unique number; storing all the labels for the plurality of nodes in a memory; creating a mask for each level; and storing the mask created for each level in the memory.