Design and analysis of query languages for structured documents. A formal and logical approach