This is the first book that provides a solid theoretical account of the foundation of the popular data format XML. Part I establishes basic concepts, starting with schemas, tree automata and pattern matching, and concluding with static typechecking for XML as a highlight of the book. In Part II, the author turns his attention to more advanced topics, including efficient 'on-the-fly' tree automata algorithms, path- and logic-based queries, tree transformation, and exact typechecking. The author provides many examples of code fragments to illustrate features, and exercises to enhance understanding. Thus the book will be ideal for students and researchers whether just beginning, or experienced in XML research.