Add a serialize() helper for element attributes