Foundations of XML Processing: Typechecking