Changed write() method to use XMLWriter