Yes, you will need to do this with code. You can either manually insert the xml into your dom, or you can look into using the ExecuteAction method to accomplish this.

Signature
Greg Collins [InfoPath MVP]
Please visit: http://www.InfoPathDev.com
How can I have an optional section inserted when i select a value in a
drop-down list? Do I have to do it with code?
The section is an "Optional Section" so it has to be added to the xml when
the option is seleted from the drop-down list.