XML is a now a dominant standard for storing and exchanging information. With its increasing use in areas such as data warehousing and e-commerce, there is a rapidly growing need for rule-based technology to support reactive functionality on XML repositories. Event-condition-action (ECA) rules automatically perform actions in response to events and are a natural facility to support such functionality. In this paper, we study ECA rules in the context of XML data. We define a simple language for specifying ECA rules on XML repositories. The language is illustrated by means of some examples, and its syntax and semantics are then specified more formally. We then investigate methods for analysing and optimising these ECA rules, a task which has added complexity in this XML setting compared with conventional active databases.