Building an element tree