It worked. Thanks anyway just needed to put

sch.WriteStartDocument(); before for loop