The first approach is invalid code. The second approach is the correct one:
XDocument.DOM.selectSingleNode("/my:myFields/my:flag").Text = "1";
What is the error you are getting?
Are you attempting to do this in an OnBeforeChange or OnValidate event handler? The DOM is readonly during those events and you will not be able to update values.
You cannot run rules from code. This is not supported. However, you can call into code from the rule condition and have your code return true or false to decide whether to run the rule. To do this, see my article "Use Code to Determine a Rule Condition":
http://www.infopathdev.com/howto/tutorials/default.aspx?i=88f921f13dec4e7cae61191bac084fffGreg Collins [InfoPath MVP]
InfoPath Dev