Having set up fields in a repeating group programmatically using XmlWriter, integer and date fields would have a red star attached, not validating at saving time, although not marked required in the data connections. It helps to add the xsi:nil="true" attribute to the element. Instead of:
writer.WriteElementString("elementName", myNamespace, "");
writer.WriteAttributeString("xsi", "nil", xsiNamespace, "true");
And voila: The fields are not mandatory any more.
I tried to use this bug as a feature, but it only works for integer and date fields, not for text fields. In order to make text fields required programmatically, just add a field in the main data connection as switch and attach the validation rule to it. When the program decides to make the fields required, set the switch.