The XML has undoubtedly become a standard for data representation and manipulation. But most of XML documents are still created without the respective description of their structure, i.e. an XML schema. In this paper, we further enhance current methods for automatic inferring of an XML schema with discovering keys and foreign keys. We do not consider sample XML data for discovery but a set of queries in XQuery and we show how constructs utilized in the queries can be used for the discovery. Categories and Subject Descriptors I.7.1 [Document and Text Processing]: Document and Text Editing – languages, document management General Terms Measurement, Algorithms Keywords DTD, XML Schema, schema inference, integrity constraints.