The underlying XmlWriter tries to be smart and sometimes writes full end tags instead of an open/close tag or vice-versa. Ensure that this is done consistently, and consider removing the dependency on XmlWriter altogether for improved cross-platform portability.