build Function to build the XML query