Constructing and validating an XML document