The problem of efficiently evaluating XPath and XQuery queries has become increasingly significant since more and more XML data is stored in its native form. We propose a novel optimisation technique for XML queries that is based on the semantic properties exhibited by XML data. In sharp contrast to previous studies on selectivity estimation we propose to specify bounds on the number of element nodes in an XML tree that form the root of isomorphic subtrees. It turns out that efficient reasoning about these constraints provides effective means to predict the number of XPath and XQuery query answers, to predict the number of updates using the XQuery update facility, to predict the number of en(de)cryptions using XML encryption, and to optimis...